mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: session基本功能及单测
This commit is contained in:
parent
4303487d32
commit
908cb1634b
|
@ -24,3 +24,5 @@ completion_api_params = {
|
|||
"frequency_penalty": 0.4,
|
||||
"presence_penalty": 0.3,
|
||||
}
|
||||
|
||||
session_expire_time = 60 * 60 * 24 * 7
|
||||
|
|
|
@ -35,6 +35,7 @@ class Session:
|
|||
# 向API请求补全
|
||||
response = pkg.openai.manager.get_inst().request_completion(self.prompt, self.user_name+':')
|
||||
|
||||
# print(response)
|
||||
# 处理回复
|
||||
res_test = response["choices"][0]["text"]
|
||||
res_ans = res_test
|
||||
|
@ -45,7 +46,7 @@ class Session:
|
|||
del (res_ans_spt[0])
|
||||
res_ans = '\n\n'.join(res_ans_spt)
|
||||
|
||||
self.prompt += "\n" + self.bot_name + ":{}".format(res_ans)
|
||||
self.prompt += "{}".format(res_ans) + '\n'
|
||||
return res_ans
|
||||
|
||||
def persistence(self):
|
||||
|
|
16
tests/test_session_console.py
Normal file
16
tests/test_session_console.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import config
|
||||
import unittest
|
||||
import pkg.openai.session
|
||||
import pkg.openai.manager
|
||||
|
||||
|
||||
class TestOpenAISession(unittest.TestCase):
|
||||
def test_session_console(self):
|
||||
interact = pkg.openai.manager.OpenAIInteract(config.openai_config['api_key'], config.completion_api_params)
|
||||
|
||||
session = pkg.openai.session.Session('test')
|
||||
print(session.append('你好'))
|
||||
print("#{}#".format(session.prompt))
|
||||
|
||||
print(session.append('你叫什么名字'))
|
||||
print("#{}#".format(session.prompt))
|
Loading…
Reference in New Issue
Block a user