yym68686 commited on
Commit
93c3f12
·
1 Parent(s): 82c93cf

Do not output response stream

Browse files
Files changed (2) hide show
  1. main.py +3 -0
  2. response.py +3 -3
main.py CHANGED
@@ -72,6 +72,9 @@ async def error_handling_wrapper(generator, status_code=200):
72
  first_item_str = first_item_str[5:]
73
  first_item_str = json.loads(first_item_str)
74
  if isinstance(first_item_str, dict) and 'error' in first_item_str:
 
 
 
75
  # 如果第一个 yield 的项是错误信息,抛出 HTTPException
76
  raise HTTPException(status_code=status_code, detail=first_item_str)
77
 
 
72
  first_item_str = first_item_str[5:]
73
  first_item_str = json.loads(first_item_str)
74
  if isinstance(first_item_str, dict) and 'error' in first_item_str:
75
+ print('\033[31m')
76
+ print(f"first_item_str: {first_item_str}")
77
+ print('\033[0m')
78
  # 如果第一个 yield 的项是错误信息,抛出 HTTPException
79
  raise HTTPException(status_code=status_code, detail=first_item_str)
80
 
response.py CHANGED
@@ -42,7 +42,7 @@ async def fetch_gemini_response_stream(client, url, headers, payload, model):
42
  buffer += chunk
43
  while "\n" in buffer:
44
  line, buffer = buffer.split("\n", 1)
45
- print(line)
46
  if line and '\"text\": \"' in line:
47
  try:
48
  json_data = json.loads( "{" + line + "}")
@@ -82,7 +82,7 @@ async def fetch_gpt_response_stream(client, url, headers, payload):
82
  buffer += chunk.decode('utf-8')
83
  while "\n" in buffer:
84
  line, buffer = buffer.split("\n", 1)
85
- print(line)
86
  yield line + "\n"
87
 
88
  async def fetch_claude_response_stream(client, url, headers, payload, model):
@@ -102,7 +102,7 @@ async def fetch_claude_response_stream(client, url, headers, payload, model):
102
  buffer += chunk.decode('utf-8')
103
  while "\n" in buffer:
104
  line, buffer = buffer.split("\n", 1)
105
- print(line)
106
 
107
  if line.startswith("data:"):
108
  print(line)
 
42
  buffer += chunk
43
  while "\n" in buffer:
44
  line, buffer = buffer.split("\n", 1)
45
+ # print(line)
46
  if line and '\"text\": \"' in line:
47
  try:
48
  json_data = json.loads( "{" + line + "}")
 
82
  buffer += chunk.decode('utf-8')
83
  while "\n" in buffer:
84
  line, buffer = buffer.split("\n", 1)
85
+ # print(line)
86
  yield line + "\n"
87
 
88
  async def fetch_claude_response_stream(client, url, headers, payload, model):
 
102
  buffer += chunk.decode('utf-8')
103
  while "\n" in buffer:
104
  line, buffer = buffer.split("\n", 1)
105
+ # print(line)
106
 
107
  if line.startswith("data:"):
108
  print(line)