forked from nladuo/live2d-chatbot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot_demo.py
44 lines (36 loc) · 957 Bytes
/
chatbot_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pyutils.live2d_control import tts_and_play_audio
import warnings
warnings.filterwarnings("ignore")
from openai import OpenAI
API_KEY = "USE YOUR OWN OPENAI API KEY"
BASE_URL = "USE YOUR OWN BASE URL"
MODEL_NAME = "CHOOSE YOUR MODEL"
def call_model(query):
client = OpenAI(
api_key=API_KEY,
base_url=BASE_URL,
)
response = client.chat.completions.create(
model=MODEL_NAME,
messages=[
{
"role": "system",
"content": "You are a helpful assistant",
},
{
"role": "user",
"content": query,
},
],
max_tokens=4096,
temperature=0,
frequency_penalty=1,
presence_penalty=1,
stream=False,
)
return response.choices[0].message.content
while True:
q = input("输入问题:")
res = call_model(q)
print(res)
tts_and_play_audio(res)