-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathapi_client.py
More file actions
34 lines (30 loc) · 1012 Bytes
/
api_client.py
File metadata and controls
34 lines (30 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from openai import OpenAI
class DeepSeekClient:
"""DeepSeek API客户端封装"""
def __init__(self, api_key: str):
"""初始化API客户端
Args:
api_key: DeepSeek API密钥
"""
self.client = OpenAI(
api_key=api_key,
base_url="https://api.deepseek.com"
)
async def chat_completion(self, messages: list, response_format: dict = None, **kwargs):
"""统一DeepSeek聊天API调用
Args:
messages: 消息列表
response_format: 响应格式要求
**kwargs: 其他API参数
Returns:
API响应内容
"""
params = {
"model": "deepseek-chat",
"messages": messages,
**kwargs
}
if response_format:
params["response_format"] = response_format
response = self.client.chat.completions.create(**params)
return response.choices[0].message.content