更改项目文件夹结构

This commit is contained in:
2023-12-10 16:31:50 +08:00
parent 8d9bd619c4
commit e00a704a56
24 changed files with 12 additions and 14 deletions

28
apiModule/gpt4Turbo.py Normal file
View File

@@ -0,0 +1,28 @@
import openai , config
openai.api_key = config.readConf()["gpt3.5turbo"]["Authorization"]
openai.base_url = config.readConf()["gpt3.5turbo"]["url"]
def service(prompt,history = ""):
if history == "":
response = openai.chat.completions.create(
model="gpt-4-1106-preview",
messages=[
{"role": "user", "content": prompt},
]
)
else:
response = openai.chat.completions.create(
model="gpt-4-1106-preview",
messages=[
{"role": "user", "content": history[1]["user"]},
{"role": "assistant", "content": history[1]["bot"]},
{"role": "user", "content": history[0]["user"]},
{"role": "assistant", "content": history[0]["bot"]},
{"role": "user", "content": prompt},
]
)
if response.choices[0].finish_reason == "stop":
return 200, response.choices[0].message.content, int(response.usage.total_tokens*45) #45倍tokens消耗
else:
return 50 , "API Error!", 0