修改chat为openai

This commit is contained in:
wanggeng 2025-07-22 10:02:00 +08:00
parent 08acbdf45d
commit 002a1e038f

View File

@ -8,14 +8,14 @@ from app.models.requirement import Requirement
from app.utils.common_util import SuccessData from app.utils.common_util import SuccessData
from app.core.security import get_current_user from app.core.security import get_current_user
client = OpenAI(
api_key="sk-P7bm1Ioe7eovIWkbabAbY8yEON2VFu4RcHqumAFCfoxDVDdi",
base_url="https://api.lkeap.cloud.tencent.com/v1"
)
# client = OpenAI( # client = OpenAI(
# api_key="sk-56a83c7c71a5459ea181bc86f0a42af9", # api_key="sk-P7bm1Ioe7eovIWkbabAbY8yEON2VFu4RcHqumAFCfoxDVDdi",
# base_url="https://api.deepseek.com/chat/completions" # base_url="https://api.lkeap.cloud.tencent.com/v1"
# ) # )
client = OpenAI(
api_key="sk-328795a17fdc4a75b993f7ca5445593a",
base_url="https://api.deepseek.com"
)
class WorkScore(BaseModel): class WorkScore(BaseModel):
@ -56,7 +56,7 @@ async def work_chat(work_score: WorkScore,
print(">>> prompt: \n%s" % prompt) print(">>> prompt: \n%s" % prompt)
messages = [{'role': 'user', 'content': prompt}] messages = [{'role': 'user', 'content': prompt}]
stream = client.chat.completions.create( stream = client.chat.completions.create(
model="deepseek-r1", model="deepseek-chat",
messages=messages, messages=messages,
stream=True stream=True
) )
@ -65,6 +65,7 @@ async def work_chat(work_score: WorkScore,
answer_content = "" # 定义完整回复 answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复 is_answering = False # 判断是否结束思考过程并开始回复
for chunk in stream: for chunk in stream:
print(chunk)
if not getattr(chunk, 'choices', None): if not getattr(chunk, 'choices', None):
print("\n" + "=" * 20 + "Token 使用情况" + "=" * 20 + "\n") print("\n" + "=" * 20 + "Token 使用情况" + "=" * 20 + "\n")
print(chunk.usage) print(chunk.usage)