Ani14 commited on
Commit
2b211fe
·
verified ·
1 Parent(s): fe78503

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -35,7 +35,10 @@ def call_llm(messages, model="deepseek/deepseek-chat-v3-0324:free", max_tokens=3
35
  "temperature": temperature,
36
  "stream": True
37
  }
 
38
  with requests.post(url, headers=headers, json=data, stream=True) as response:
 
 
39
  if line:
40
  decoded = line.decode("utf-8")
41
  if decoded.startswith("data: "):
@@ -47,10 +50,9 @@ def call_llm(messages, model="deepseek/deepseek-chat-v3-0324:free", max_tokens=3
47
  token = delta.get("content", "")
48
  if token:
49
  content += token
50
- yield content
51
- yield content
52
- except:
53
- continue
54
 
55
 
56
  def get_sources(topic, domains=None):
 
35
  "temperature": temperature,
36
  "stream": True
37
  }
38
+
39
  with requests.post(url, headers=headers, json=data, stream=True) as response:
40
+ content = ""
41
+ for line in response.iter_lines():
42
  if line:
43
  decoded = line.decode("utf-8")
44
  if decoded.startswith("data: "):
 
50
  token = delta.get("content", "")
51
  if token:
52
  content += token
53
+ yield token # Yield only the new token, not full content each time
54
+ except json.JSONDecodeError:
55
+ pass
 
56
 
57
 
58
  def get_sources(topic, domains=None):