ParthSadaria commited on
Commit
a01be99
·
verified ·
1 Parent(s): 8ce4a3a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -3
main.py CHANGED
@@ -65,18 +65,21 @@ def generate_search(query: str, stream: bool = True) -> str:
65
  json_modified_value = json.loads(value[6:])
66
  content = json_modified_value.get("choices", [{}])[0].get("delta", {}).get("content", "")
67
  if stream:
68
- yield f"data: {json.dumps({'choices': [{'delta': {'content': content}}]})}\n\n"
 
69
  streaming_text += content
70
  except json.JSONDecodeError:
71
  continue
72
 
73
  if not stream:
74
- yield json.dumps({
 
75
  "choices": [{
76
  "message": {"content": streaming_text},
77
  "finish_reason": "stop"
78
  }]
79
- })
 
80
  @app.get("/searchgpt")
81
  async def search_gpt(q: str, stream: Optional[bool] = False):
82
  if not q:
 
65
  json_modified_value = json.loads(value[6:])
66
  content = json_modified_value.get("choices", [{}])[0].get("delta", {}).get("content", "")
67
  if stream:
68
+ # Don't double-encode the JSON
69
+ yield f"data: {json_modified_value}\n\n"
70
  streaming_text += content
71
  except json.JSONDecodeError:
72
  continue
73
 
74
  if not stream:
75
+ # Return a proper JSON response without double encoding
76
+ yield {
77
  "choices": [{
78
  "message": {"content": streaming_text},
79
  "finish_reason": "stop"
80
  }]
81
+ }
82
+
83
  @app.get("/searchgpt")
84
  async def search_gpt(q: str, stream: Optional[bool] = False):
85
  if not q: