Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl_ai_recommender
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
闫发泽
ydl_ai_recommender
Commits
31041a93
Commit
31041a93
authored
Mar 01, 2023
by
柴鹏飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精排模型接口
parent
0a597634
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
rank_service.py
src/service/rank_service.py
+80
-0
No files found.
src/service/rank_service.py
0 → 100644
View file @
31041a93
# -*- coding: utf-8 -*-
import
json
from
concurrent.futures
import
ThreadPoolExecutor
import
tornado.web
import
tornado.ioloop
import
tornado.options
import
tornado.httpserver
from
tornado.concurrent
import
run_on_executor
from
ydl_ai_recommender.src.utils.log
import
create_logger
from
ydl_ai_recommender.src.core.rank.ranker
import
Ranker
logger
=
create_logger
(
__name__
,
'rank_service.log'
,
is_rotating
=
True
)
ranker
=
Ranker
()
class
RankHandler
(
tornado
.
web
.
RequestHandler
):
executor
=
ThreadPoolExecutor
(
1
)
@tornado.gen.coroutine
def
get
(
self
):
uid
=
self
.
get_argument
(
'uid'
,
None
)
if
uid
is
None
:
logger
.
warn
(
'请求参数不正确,无uid'
)
counselors
=
self
.
get_argument
(
'counselors'
,
''
)
ret
=
yield
self
.
run
(
uid
,
counselors
)
self
.
write
(
ret
)
@tornado.gen.coroutine
def
post
(
self
):
param
=
json
.
loads
(
self
.
request
.
body
.
decode
(
'utf-8'
))
uid
=
param
.
get
(
'uid'
,
None
)
counselors
=
param
.
get
(
'counselors'
,
''
)
if
uid
is
None
:
logger
.
warn
(
'请求参数不正确,无uid'
)
ret
=
yield
self
.
run
(
uid
,
counselors
)
self
.
write
(
ret
)
@run_on_executor
def
run
(
self
,
uid
,
counselors
=
''
):
logger
.
info
(
'request@@uid=
%
s@@counselors=
%
s'
,
uid
,
counselors
)
try
:
rank_result
=
ranker
.
rank
(
uid
,
counselors
)
ret
=
{
'status'
:
'success'
,
'code'
:
0
,
'data'
:
rank_result
,
'total_count'
:
len
(
rank_result
),
}
except
Exception
as
e
:
logger
.
error
(
'执行精排报错'
,
exc_info
=
True
)
ret
=
{
'status'
:
'error'
,
'code'
:
1
,
'data'
:
[],
'total_count'
:
0
,
}
ret_str
=
json
.
dumps
(
ret
,
ensure_ascii
=
False
)
logger
.
info
(
'response@@uid=
%
s@@counselors=
%
s@@ret=
%
s'
,
uid
,
counselors
,
ret_str
)
return
ret
if
__name__
==
'__main__'
:
tornado
.
options
.
define
(
'port'
,
default
=
8868
,
type
=
int
,
help
=
'服务启动的端口号'
)
tornado
.
options
.
parse_command_line
()
app
=
tornado
.
web
.
Application
(
handlers
=
[(
r'/ai_counselor_rank'
,
RankHandler
)],
autoreload
=
False
,
debug
=
False
)
http_server
=
tornado
.
httpserver
.
HTTPServer
(
app
)
http_server
.
listen
(
tornado
.
options
.
options
.
port
)
tornado
.
ioloop
.
IOLoop
.
instance
()
.
start
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment