Spaces:
Sleeping
Sleeping
Commit
·
bec1d7f
1
Parent(s):
e2a5eb1
làm mọi thứ đẹp lại
Browse files- call_api.py +11 -12
call_api.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
from openai import OpenAI # type: ignore
|
|
|
|
|
2 |
def call_openai(
|
3 |
user_prompt,
|
4 |
chat_history: list[tuple[str, str]],
|
@@ -51,6 +53,8 @@ def call_openai(
|
|
51 |
print("\n")
|
52 |
yield response #chat reply
|
53 |
|
|
|
|
|
54 |
def call_deepseek(
|
55 |
user_prompt: str,
|
56 |
chat_history: list[tuple[str, str]],
|
@@ -68,21 +72,16 @@ def call_deepseek(
|
|
68 |
- reply (str): nội dung model sinh ra.
|
69 |
"""
|
70 |
# 1. Xử lý tùy chọn file (nếu có)
|
71 |
-
if file_upload
|
72 |
try:
|
73 |
-
|
74 |
-
|
75 |
-
# TODO: xử lý hoặc đính kèm file_bytes vào prompt nếu cần
|
76 |
-
except Exception:
|
77 |
pass
|
78 |
|
79 |
-
|
80 |
-
if image_upload is not None:
|
81 |
try:
|
82 |
-
|
83 |
-
|
84 |
-
# TODO: xử lý img nếu cần
|
85 |
-
except Exception:
|
86 |
pass
|
87 |
|
88 |
# 3. Xây dựng messages lịch sử chat
|
@@ -96,7 +95,7 @@ def call_deepseek(
|
|
96 |
messages.append({"role": "user", "content": user_prompt})
|
97 |
|
98 |
# 4. Gọi API DeepSeek Chat (OpenAI-compatible)
|
99 |
-
response =
|
100 |
model="deepseek-chat", # hoặc model bạn cấu hình
|
101 |
messages=messages,
|
102 |
temperature=temperature,
|
|
|
1 |
from openai import OpenAI # type: ignore
|
2 |
+
|
3 |
+
|
4 |
def call_openai(
|
5 |
user_prompt,
|
6 |
chat_history: list[tuple[str, str]],
|
|
|
53 |
print("\n")
|
54 |
yield response #chat reply
|
55 |
|
56 |
+
|
57 |
+
deepseek = OpenAI(api_key="DEEPSEEK_API_KEY", base_url="https://api.deepseek.com")
|
58 |
def call_deepseek(
|
59 |
user_prompt: str,
|
60 |
chat_history: list[tuple[str, str]],
|
|
|
72 |
- reply (str): nội dung model sinh ra.
|
73 |
"""
|
74 |
# 1. Xử lý tùy chọn file (nếu có)
|
75 |
+
if file_upload == None:
|
76 |
try:
|
77 |
+
pass
|
78 |
+
except:
|
|
|
|
|
79 |
pass
|
80 |
|
81 |
+
if image_upload == None:
|
|
|
82 |
try:
|
83 |
+
pass
|
84 |
+
except:
|
|
|
|
|
85 |
pass
|
86 |
|
87 |
# 3. Xây dựng messages lịch sử chat
|
|
|
95 |
messages.append({"role": "user", "content": user_prompt})
|
96 |
|
97 |
# 4. Gọi API DeepSeek Chat (OpenAI-compatible)
|
98 |
+
response = deepseek.chat.completions.create(
|
99 |
model="deepseek-chat", # hoặc model bạn cấu hình
|
100 |
messages=messages,
|
101 |
temperature=temperature,
|