nanova commited on
Commit
ebfa154
·
1 Parent(s): a1e2b25

feat: update

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -13,10 +13,10 @@ API_TOKEN = os.getenv("API_TOKEN")
13
 
14
  # 验证必要的环境变量
15
  if not API_URL or not API_TOKEN:
16
- raise ValueError("make sure API_URL & API_TOKEN is right")
17
 
18
  print(f"[INFO] starting:")
19
- print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-13:]}")
20
  print(f"[INFO] API_TOKEN: {API_TOKEN[:10]}...{API_TOKEN[-10:]}") # 只显示token的前10位和后10位
21
 
22
  """
@@ -63,7 +63,6 @@ def respond(
63
  print(f"[INFO] reqData: {data}")
64
 
65
  response = ""
66
- current_response = ""
67
 
68
  with requests.post(API_URL, headers=headers, json=data, stream=True) as r:
69
  for line in r.iter_lines():
@@ -73,18 +72,10 @@ def respond(
73
  if 'choices' in json_response and len(json_response['choices']) > 0:
74
  token = json_response['choices'][0].get('delta', {}).get('content', '')
75
  if token:
76
- current_response += token
77
- if '**Final Answer**' in current_response:
78
- final_answer = current_response.split('**Final Answer**')[-1].strip()
79
- if final_answer:
80
- yield final_answer
81
  except json.JSONDecodeError:
82
  continue
83
-
84
- if current_response and '**Final Answer**' in current_response:
85
- final_answer = current_response.split('**Final Answer**')[-1].strip()
86
- if final_answer:
87
- yield final_answer
88
 
89
 
90
  """
 
13
 
14
  # 验证必要的环境变量
15
  if not API_URL or not API_TOKEN:
16
+ raise ValueError("请确保设置了环境变量 API_URL API_TOKEN")
17
 
18
  print(f"[INFO] starting:")
19
+ print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-12:]}")
20
  print(f"[INFO] API_TOKEN: {API_TOKEN[:10]}...{API_TOKEN[-10:]}") # 只显示token的前10位和后10位
21
 
22
  """
 
63
  print(f"[INFO] reqData: {data}")
64
 
65
  response = ""
 
66
 
67
  with requests.post(API_URL, headers=headers, json=data, stream=True) as r:
68
  for line in r.iter_lines():
 
72
  if 'choices' in json_response and len(json_response['choices']) > 0:
73
  token = json_response['choices'][0].get('delta', {}).get('content', '')
74
  if token:
75
+ response += token
76
+ yield response
 
 
 
77
  except json.JSONDecodeError:
78
  continue
 
 
 
 
 
79
 
80
 
81
  """