Skip to content

Commit

Permalink
add chatbot (InternLM#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvhan028 authored Jun 18, 2023
1 parent a75c0a4 commit ef2adb0
Show file tree
Hide file tree
Showing 11 changed files with 722 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ repos:
rev: v0.2.0
hooks:
- id: check-copyright
args: []
args: ["llmdeploy"]
1 change: 1 addition & 0 deletions llmdeploy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) OpenMMLab. All rights reserved.
1 change: 1 addition & 0 deletions llmdeploy/serve/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Copyright (c) OpenMMLab. All rights reserved.
38 changes: 38 additions & 0 deletions llmdeploy/serve/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os

import fire

from llmdeploy.serve.fastertransformer.chatbot import Chatbot


def input_prompt():
print('\ndouble enter to end input >>> ', end='')
sentinel = '' # ends when this string is seen
return '\n'.join(iter(input, sentinel))


def main(triton_server_addr: str, model_name: str, session_id: int):
log_level = os.environ.get('SERVICE_LOG_LEVEL', 'INFO')
chatbot = Chatbot(triton_server_addr,
model_name,
log_level=log_level,
display=True)
nth_round = 1
while True:
prompt = input_prompt()
if prompt == 'exit':
exit(0)
elif prompt == 'end':
chatbot.end(session_id)
else:
request_id = f'{session_id}-{nth_round}'
for status, res, tokens in chatbot.stream_infer(
session_id, prompt, request_id=request_id):
continue
print(f'session {session_id}, {status}, {tokens}, {res}')
nth_round += 1


if __name__ == '__main__':
fire.Fire(main)
3 changes: 3 additions & 0 deletions llmdeploy/serve/fastertransformer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) OpenMMLab. All rights reserved.
from llmdeploy.serve.fastertransformer.chatbot import \
Chatbot # noqa: F401,F403
Loading

0 comments on commit ef2adb0

Please sign in to comment.