This commit is contained in:
parent
222c46ef15
commit
2cfc960bc3
|
|
@ -19,7 +19,7 @@ def chat(user_message, history, max_tokens, temperature):
|
||||||
}
|
}
|
||||||
payload = {
|
payload = {
|
||||||
"model": MODEL_NAME,
|
"model": MODEL_NAME,
|
||||||
"prompt": prompt,
|
"text": prompt, # ✅ 注意是 text,不是 prompt
|
||||||
"max_tokens": max_tokens,
|
"max_tokens": max_tokens,
|
||||||
"temperature": temperature
|
"temperature": temperature
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ def chat(user_message, history, max_tokens, temperature):
|
||||||
try:
|
try:
|
||||||
response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
|
response = requests.post(API_URL, headers=headers, json=payload, timeout=30)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
reply = result["text"].strip() # ✅ /generate 接口返回字段是 text
|
reply = result["text"].strip() # ✅ generate 接口返回字段是 text
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
reply = f"[请求失败] {e}"
|
reply = f"[请求失败] {e}"
|
||||||
|
|
||||||
|
|
@ -41,14 +41,14 @@ def test_api_connection(max_tokens, temperature):
|
||||||
}
|
}
|
||||||
payload = {
|
payload = {
|
||||||
"model": MODEL_NAME,
|
"model": MODEL_NAME,
|
||||||
"prompt": "Ping?",
|
"text": "Ping?", # ✅ 也改成 text 字段
|
||||||
"max_tokens": max_tokens,
|
"max_tokens": max_tokens,
|
||||||
"temperature": temperature
|
"temperature": temperature
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resp = requests.post(API_URL, headers=headers, json=payload, timeout=10)
|
resp = requests.post(API_URL, headers=headers, json=payload, timeout=10)
|
||||||
out = resp.json()["text"].strip() # ✅ 修改这里
|
out = resp.json()["text"].strip()
|
||||||
return f"✅ API 可用,响应: {out}"
|
return f"✅ API 可用,响应: {out}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"❌ API 请求失败: {e}"
|
return f"❌ API 请求失败: {e}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue