lowesyang commited on
Commit
55e701e
·
1 Parent(s): b9c7bd3
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -4,8 +4,10 @@ import json
4
  import os
5
  from dotenv import load_dotenv
6
 
 
7
  load_dotenv()
8
 
 
9
  API_URL = os.getenv("API_URL")
10
  API_TOKEN = os.getenv("API_TOKEN")
11
 
@@ -22,7 +24,7 @@ For more information on `huggingface_hub` Inference API support, please check th
22
 
23
  def respond(
24
  message,
25
- history: list[dict],
26
  system_message,
27
  max_tokens,
28
  temperature,
@@ -57,13 +59,13 @@ def respond(
57
 
58
  try:
59
  with requests.post(API_URL, headers=headers, json=data) as r:
60
- print(f"[INFO] response status: {r.status_code}")
61
  if r.status_code == 200:
62
  json_response = r.json()
63
- print(f"[INFO] response json: {json_response}")
64
  if 'choices' in json_response and len(json_response['choices']) > 0:
65
  content = json_response['choices'][0].get('message', {}).get('content', '')
66
- print(f"[INFO] response content: {content}")
67
  if content:
68
  if '<think>' in content and '</think>' in content:
69
  content = content.split('</think>')[-1].strip()
 
4
  import os
5
  from dotenv import load_dotenv
6
 
7
+ # 加载.env文件中的环境变量
8
  load_dotenv()
9
 
10
+ # 从环境变量中读取配置
11
  API_URL = os.getenv("API_URL")
12
  API_TOKEN = os.getenv("API_TOKEN")
13
 
 
24
 
25
  def respond(
26
  message,
27
+ history: list[dict], # 修改为新的消息格式
28
  system_message,
29
  max_tokens,
30
  temperature,
 
59
 
60
  try:
61
  with requests.post(API_URL, headers=headers, json=data) as r:
62
+ # print(f"[INFO] response status: {r.status_code}")
63
  if r.status_code == 200:
64
  json_response = r.json()
65
+ # print(f"[INFO] response json: {json_response}")
66
  if 'choices' in json_response and len(json_response['choices']) > 0:
67
  content = json_response['choices'][0].get('message', {}).get('content', '')
68
+ # print(f"[INFO] response content: {content}")
69
  if content:
70
  if '<think>' in content and '</think>' in content:
71
  content = content.split('</think>')[-1].strip()