|
@@ -0,0 +1,40 @@
|
|
|
+"""
|
|
|
+deep_seek 官方 API
|
|
|
+"""
|
|
|
+import json
|
|
|
+from openai import OpenAI
|
|
|
+
|
|
|
+from config import deep_seek_official_model
|
|
|
+from config import deep_seek_official_api_key
|
|
|
+
|
|
|
+def fetch_deepseek_response(model, prompt, output_type='text'):
|
|
|
+ """
|
|
|
+ deep_seek方法
|
|
|
+ """
|
|
|
+ client = OpenAI(
|
|
|
+ api_key=deep_seek_official_api_key,
|
|
|
+ base_url="https://api.deepseek.com"
|
|
|
+ )
|
|
|
+
|
|
|
+ # get response format
|
|
|
+ if output_type == "json":
|
|
|
+ response_format = {"type": "json_object"}
|
|
|
+ else:
|
|
|
+ response_format = {"type": "text"}
|
|
|
+
|
|
|
+ chat_completion = client.chat.completions.create(
|
|
|
+ messages=[
|
|
|
+ {
|
|
|
+ "role": "user",
|
|
|
+ "content": prompt,
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ model=deep_seek_official_model.get(model, "deepseek-chat"),
|
|
|
+ response_format=response_format,
|
|
|
+ )
|
|
|
+ response = chat_completion.choices[0].message.content
|
|
|
+ if output_type == "json":
|
|
|
+ response_json = json.loads(response)
|
|
|
+ return response_json
|
|
|
+
|
|
|
+ return response
|