From c53f4c9049f269cf79aeea0a82d3bbb1877eff77 Mon Sep 17 00:00:00 2001 From: shuiyu1123 Date: Sat, 20 Jun 2026 14:47:16 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0system=5Fprompt=E5=92=8Cmax?= =?UTF-8?q?=5Ftokens=E5=8F=82=E6=95=B0=20-=20=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=A7=92=E8=89=B2=E8=AE=BE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_correction.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/api_correction.py b/api_correction.py index 3a25941..d230cfb 100644 --- a/api_correction.py +++ b/api_correction.py @@ -24,20 +24,23 @@ SYSTEM_PROMPT = """你是一个名叫小狸的8岁中国小女孩。 3. 回答简洁但要说清楚,不要讲一半就停""" -def call_astron(q, temperature=0.85): +def call_astron(q, temperature=0.85, system_prompt=None, max_tokens=8192): + """调用Astron API,支持自定义system prompt""" + if system_prompt is None: + system_prompt = SYSTEM_PROMPT for attempt in range(3): try: headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ASTRON_KEY}"} payload = { "model": ASTRON_MODEL, "messages": [ - {"role": "system", "content": SYSTEM_PROMPT}, + {"role": "system", "content": system_prompt}, {"role": "user", "content": q} ], "temperature": temperature, - "max_tokens": 8192, + "max_tokens": max_tokens, } - resp = requests.post(ASTRON_URL, headers=headers, json=payload, timeout=60) + resp = requests.post(ASTRON_URL, headers=headers, json=payload, timeout=120) if resp.status_code == 200: content = resp.json()['choices'][0]['message']['content'].strip() if content: