48 lines
2.3 KiB
Python
48 lines
2.3 KiB
Python
from openai import OpenAI
|
|
|
|
# client = OpenAI(
|
|
# base_url="https://api.deepseek.com/v1",
|
|
# api_key="sk-01931083835f4a539e368b209559c52c",
|
|
# )
|
|
# response = client.chat.completions.create(
|
|
# model="deepseek-chat",
|
|
# messages=[
|
|
# {"role": "system", "content": "你是谁"},
|
|
# ],
|
|
# stream=True,
|
|
# )
|
|
|
|
# for chunk in response:
|
|
# if chunk.choices[0].delta.content is not None:
|
|
# print(chunk.choices[0].delta.content, end="", flush=True)
|
|
|
|
# 调用自己写的
|
|
from openai_client import OpenAI
|
|
|
|
client = OpenAI(
|
|
base_url="https://api.deepseek.com",
|
|
api_key="sk-cc7b983a00f34cec9a12b19b64060f68",
|
|
)
|
|
response = client.chat.completions.create(
|
|
model="deepseek-chat",
|
|
messages=[
|
|
{"role": "system", "content": "西游记作者是谁"},
|
|
],
|
|
stream=True,
|
|
)
|
|
# print(response.choices[0].message.content)
|
|
for chunk in response:
|
|
if chunk.choices[0].delta.content is not None:
|
|
print(chunk.choices[0].delta.content, end="", flush=True)
|
|
|
|
|
|
# ChatCompletion(
|
|
# id='f8170d75-875c-4b46-bd3b-82a93d6be4c0',
|
|
# choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='你好!我是DeepSeek,一个由深度求索公司创造的AI助手。😊\n\n我是一个纯文本模型,虽然不支持多模态识别功能,但我有文件上传功能,可以帮你处理图像、txt、pdf、ppt、word、excel等文件,并从中读取文字信息进行分析处理。我完全免费使用,拥有128K的上下文长度,还支持联网搜索功能(需要你在Web/App中手动点开联网搜索按键)。\n\n你可以通过官方应用商店下载我的App来使用我。我很乐意帮助你解答问题、处理文档、进行对话交流等等!\n\n有什么我可以帮助你的吗?无论是学习、工作还是日常问题,我都很愿意为你提供帮助!✨', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None))],
|
|
# created=1765348625,
|
|
# model='deepseek-chat',
|
|
# object='chat.completion',
|
|
# service_tier=None,
|
|
# system_fingerprint='fp_eaab8d114b_prod0820_fp8_kvcache',
|
|
# usage=CompletionUsage(completion_tokens=143, prompt_tokens=4, total_tokens=147, completion_tokens_details=None, prompt_tokens_details=PromptTokensDetails(audio_tokens=None, cached_tokens=0), prompt_cache_hit_tokens=0, prompt_cache_miss_tokens=4))
|