Spaces:
Sleeping
Sleeping
Update ai_utils.py
Browse files- ai_utils.py +2 -18
ai_utils.py
CHANGED
@@ -3,22 +3,6 @@ from config import get_ai71_api_key
|
|
3 |
|
4 |
AI71_API_KEY = get_ai71_api_key()
|
5 |
|
6 |
-
"""
|
7 |
-
def generate_response(system_message, user_message):
|
8 |
-
response_text = ""
|
9 |
-
for chunk in AI71(AI71_API_KEY).chat.completions.create(
|
10 |
-
model="tiiuae/falcon-180b-chat",
|
11 |
-
messages=[
|
12 |
-
{"role": "system", "content": system_message},
|
13 |
-
{"role": "user", "content": user_message},
|
14 |
-
],
|
15 |
-
stream=True,
|
16 |
-
):
|
17 |
-
if chunk.choices[0].delta.content:
|
18 |
-
response_text += chunk.choices[0].delta.content
|
19 |
-
return response_text
|
20 |
-
"""
|
21 |
-
|
22 |
def generate_response(system_message, user_message):
|
23 |
response_text = ""
|
24 |
for chunk in AI71(AI71_API_KEY).chat.completions.create(
|
@@ -33,6 +17,6 @@ def generate_response(system_message, user_message):
|
|
33 |
response_text += chunk.choices[0].delta.content
|
34 |
|
35 |
# Ensure no extra characters or unfinished text is appended
|
36 |
-
response_text = response_text.
|
37 |
|
38 |
-
return response_text
|
|
|
3 |
|
4 |
AI71_API_KEY = get_ai71_api_key()
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def generate_response(system_message, user_message):
|
7 |
response_text = ""
|
8 |
for chunk in AI71(AI71_API_KEY).chat.completions.create(
|
|
|
17 |
response_text += chunk.choices[0].delta.content
|
18 |
|
19 |
# Ensure no extra characters or unfinished text is appended
|
20 |
+
response_text = response_text.strip()
|
21 |
|
22 |
+
return response_text
|