Spaces:
Runtime error
Runtime error
lewisliuX123
commited on
Commit
·
8c28a6b
1
Parent(s):
c018e63
Update bot/chatgpt/chat_gpt_bot.py
Browse files- bot/chatgpt/chat_gpt_bot.py +8 -10
bot/chatgpt/chat_gpt_bot.py
CHANGED
@@ -26,9 +26,9 @@ class ChatGPTBot(Bot):
|
|
26 |
new_query = Session.build_session_query(query, from_user_id)
|
27 |
logger.debug("[OPEN_AI] session query={}".format(new_query))
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
reply_content = self.reply_text(new_query, from_user_id, 0)
|
34 |
logger.debug("[OPEN_AI] new_query={}, user={}, reply_cont={}".format(new_query, from_user_id, reply_content))
|
@@ -42,18 +42,16 @@ class ChatGPTBot(Bot):
|
|
42 |
def reply_text(self, query, user_id, retry_count=0):
|
43 |
try:
|
44 |
response = openai.ChatCompletion.create(
|
45 |
-
model="
|
46 |
messages=query,
|
47 |
temperature=1, # 值在[0,1]之间,越大表示回复越具有不确定性
|
48 |
-
max_tokens=
|
49 |
-
top_p=1
|
50 |
-
frequency_penalty=0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
|
51 |
-
presence_penalty=0, # [-2,2]之间,该值越大则更倾向于产生不同的内容
|
52 |
)
|
53 |
# res_content = response.choices[0]['text'].strip().replace('<|endoftext|>', '')
|
54 |
-
logger.info(response
|
55 |
# log.info("[OPEN_AI] reply={}".format(res_content))
|
56 |
-
return response
|
57 |
except openai.error.RateLimitError as e:
|
58 |
# rate limit exception
|
59 |
logger.warn(e)
|
|
|
26 |
new_query = Session.build_session_query(query, from_user_id)
|
27 |
logger.debug("[OPEN_AI] session query={}".format(new_query))
|
28 |
|
29 |
+
if context.get('stream'):
|
30 |
+
# reply in stream
|
31 |
+
return self.reply_text_stream(query, new_query, from_user_id)
|
32 |
|
33 |
reply_content = self.reply_text(new_query, from_user_id, 0)
|
34 |
logger.debug("[OPEN_AI] new_query={}, user={}, reply_cont={}".format(new_query, from_user_id, reply_content))
|
|
|
42 |
def reply_text(self, query, user_id, retry_count=0):
|
43 |
try:
|
44 |
response = openai.ChatCompletion.create(
|
45 |
+
model="chinese-llama-alpaca-2", # 对话模型的名称
|
46 |
messages=query,
|
47 |
temperature=1, # 值在[0,1]之间,越大表示回复越具有不确定性
|
48 |
+
max_tokens=2048, # 回复最大的字符数
|
49 |
+
top_p=1
|
|
|
|
|
50 |
)
|
51 |
# res_content = response.choices[0]['text'].strip().replace('<|endoftext|>', '')
|
52 |
+
logger.info(response)
|
53 |
# log.info("[OPEN_AI] reply={}".format(res_content))
|
54 |
+
return response
|
55 |
except openai.error.RateLimitError as e:
|
56 |
# rate limit exception
|
57 |
logger.warn(e)
|