lowesyang commited on
Commit
dbdc900
·
1 Parent(s): 8072750
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -11,13 +11,12 @@ load_dotenv()
11
  API_URL = os.getenv("API_URL")
12
  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")
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
  """
23
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
@@ -56,10 +55,7 @@ def respond(
56
  }
57
 
58
  print(f"[INFO] process user msg...")
59
- print(f"[INFO] sysMsg: {system_message}")
60
  print(f"[INFO] userMsg: {message}")
61
- print(f"[INFO] modelParam: temperature={temperature}, top_p={top_p}")
62
- print(f"[INFO] reqData: {data}")
63
 
64
  try:
65
  with requests.post(API_URL, headers=headers, json=data) as r:
@@ -68,8 +64,8 @@ def respond(
68
  if 'choices' in json_response and len(json_response['choices']) > 0:
69
  content = json_response['choices'][0].get('message', {}).get('content', '')
70
  if content:
71
- # if '<think>' in content and '</think>' in content:
72
- # content = content.split('</think>')[-1].strip()
73
  print(f"[INFO] response: {content}")
74
  return content
75
  return "Service temporarily unavailable"
@@ -95,7 +91,7 @@ demo = gr.ChatInterface(
95
  label="Top-p (nucleus sampling)",
96
  ),
97
  ],
98
- type="messages" # 指定使用新的消息格式
99
  )
100
 
101
 
 
11
  API_URL = os.getenv("API_URL")
12
  API_TOKEN = os.getenv("API_TOKEN")
13
 
 
14
  if not API_URL or not API_TOKEN:
15
+ raise ValueError("invalid API_URL || API_TOKEN")
16
 
17
  print(f"[INFO] starting:")
18
  print(f"[INFO] API_URL: {API_URL[:6]}...{API_URL[-12:]}")
19
+ print(f"[INFO] API_TOKEN: {API_TOKEN[:10]}...{API_TOKEN[-10:]}")
20
 
21
  """
22
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
55
  }
56
 
57
  print(f"[INFO] process user msg...")
 
58
  print(f"[INFO] userMsg: {message}")
 
 
59
 
60
  try:
61
  with requests.post(API_URL, headers=headers, json=data) as r:
 
64
  if 'choices' in json_response and len(json_response['choices']) > 0:
65
  content = json_response['choices'][0].get('message', {}).get('content', '')
66
  if content:
67
+ if '<think>' in content and '</think>' in content:
68
+ content = content.split('</think>')[-1].strip()
69
  print(f"[INFO] response: {content}")
70
  return content
71
  return "Service temporarily unavailable"
 
91
  label="Top-p (nucleus sampling)",
92
  ),
93
  ],
94
+ type="messages"
95
  )
96
 
97