Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -124,30 +124,24 @@ def get_ai_response(messages, model="openai/gpt-3.5-turbo"):
|
|
124 |
full_response = ""
|
125 |
buffer = ""
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
lines
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
full_response += content
|
146 |
-
yield full_response
|
147 |
-
except json.JSONDecodeError:
|
148 |
-
continue
|
149 |
-
except Exception as e:
|
150 |
-
continue
|
151 |
|
152 |
except requests.exceptions.Timeout:
|
153 |
yield "Request timed out. Please try again with a shorter message or different model."
|
@@ -177,14 +171,14 @@ with st.sidebar:
|
|
177 |
|
178 |
st.divider()
|
179 |
|
180 |
-
# Model selection with working models
|
181 |
models = [
|
182 |
("GPT-3.5 Turbo", "openai/gpt-3.5-turbo"),
|
183 |
("GPT-4", "openai/gpt-4"),
|
184 |
("Claude 3 Haiku", "anthropic/claude-3-haiku"),
|
185 |
("Gemini Pro", "google/gemini-pro"),
|
186 |
-
("Llama 3.1 8B
|
187 |
-
("Llama 3.1 70B
|
188 |
("Llama 3.2 3B (Free)", "meta-llama/llama-3.2-3b-instruct:free"),
|
189 |
("Qwen 2 7B (Free)", "qwen/qwen-2-7b-instruct:free"),
|
190 |
("Phi-3 Mini (Free)", "microsoft/phi-3-mini-128k-instruct:free"),
|
|
|
124 |
full_response = ""
|
125 |
buffer = ""
|
126 |
|
127 |
+
# Using your working streaming logic
|
128 |
+
for line in response.iter_lines():
|
129 |
+
if line:
|
130 |
+
# The server sends lines starting with "data: ..."
|
131 |
+
if line.startswith(b"data: "):
|
132 |
+
data_str = line[len(b"data: "):].decode("utf-8")
|
133 |
+
if data_str.strip() == "[DONE]":
|
134 |
+
break
|
135 |
+
try:
|
136 |
+
data = json.loads(data_str)
|
137 |
+
delta = data["choices"][0]["delta"].get("content", "")
|
138 |
+
if delta:
|
139 |
+
full_response += delta
|
140 |
+
yield full_response
|
141 |
+
except json.JSONDecodeError:
|
142 |
+
continue
|
143 |
+
except (KeyError, IndexError):
|
144 |
+
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
except requests.exceptions.Timeout:
|
147 |
yield "Request timed out. Please try again with a shorter message or different model."
|
|
|
171 |
|
172 |
st.divider()
|
173 |
|
174 |
+
# Model selection with working models (based on your working code)
|
175 |
models = [
|
176 |
("GPT-3.5 Turbo", "openai/gpt-3.5-turbo"),
|
177 |
("GPT-4", "openai/gpt-4"),
|
178 |
("Claude 3 Haiku", "anthropic/claude-3-haiku"),
|
179 |
("Gemini Pro", "google/gemini-pro"),
|
180 |
+
("Llama 3.1 8B", "meta-llama/llama-3.1-8b-instruct"),
|
181 |
+
("Llama 3.1 70B", "meta-llama/llama-3.1-70b-instruct"),
|
182 |
("Llama 3.2 3B (Free)", "meta-llama/llama-3.2-3b-instruct:free"),
|
183 |
("Qwen 2 7B (Free)", "qwen/qwen-2-7b-instruct:free"),
|
184 |
("Phi-3 Mini (Free)", "microsoft/phi-3-mini-128k-instruct:free"),
|