增加system_prompt和max_tokens参数 - 支持自定义角色设定
This commit is contained in:
1 parent
2bb3b60f18
commit
c53f4c9049
1 file changed
+7
-4
+7
-4
@@ -24,20 +24,23 @@ SYSTEM_PROMPT = """你是一个名叫小狸的8岁中国小女孩。
|
|||||||
3. 回答简洁但要说清楚,不要讲一半就停"""
|
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):
|
for attempt in range(3):
|
||||||
try:
|
try:
|
||||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ASTRON_KEY}"}
|
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ASTRON_KEY}"}
|
||||||
payload = {
|
payload = {
|
||||||
"model": ASTRON_MODEL,
|
"model": ASTRON_MODEL,
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "system", "content": SYSTEM_PROMPT},
|
{"role": "system", "content": system_prompt},
|
||||||
{"role": "user", "content": q}
|
{"role": "user", "content": q}
|
||||||
],
|
],
|
||||||
"temperature": temperature,
|
"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:
|
if resp.status_code == 200:
|
||||||
content = resp.json()['choices'][0]['message']['content'].strip()
|
content = resp.json()['choices'][0]['message']['content'].strip()
|
||||||
if content:
|
if content:
|
||||||
|
|||||||
Reference in new issue
Block a user