🐛 Bug: 1. Fix the bug where system_prompt is undefined
Browse files- request.py +2 -1
- test/provider_test.py +2 -2
- utils.py +1 -1
request.py
CHANGED
@@ -251,6 +251,7 @@ async def get_claude_payload(request, engine, provider):
|
|
251 |
url = provider['base_url']
|
252 |
|
253 |
messages = []
|
|
|
254 |
for msg in request.messages:
|
255 |
name = None
|
256 |
if isinstance(msg.content, list):
|
@@ -322,7 +323,7 @@ async def get_claude_payload(request, engine, provider):
|
|
322 |
payload = {
|
323 |
"model": model,
|
324 |
"messages": messages,
|
325 |
-
"system": system_prompt,
|
326 |
}
|
327 |
|
328 |
miss_fields = [
|
|
|
251 |
url = provider['base_url']
|
252 |
|
253 |
messages = []
|
254 |
+
system_prompt = None
|
255 |
for msg in request.messages:
|
256 |
name = None
|
257 |
if isinstance(msg.content, list):
|
|
|
323 |
payload = {
|
324 |
"model": model,
|
325 |
"messages": messages,
|
326 |
+
"system": system_prompt or "You are Claude, a large language model trained by Anthropic.",
|
327 |
}
|
328 |
|
329 |
miss_fields = [
|
test/provider_test.py
CHANGED
@@ -14,7 +14,7 @@ def test_client():
|
|
14 |
def api_key():
|
15 |
return os.environ.get("API")
|
16 |
|
17 |
-
def test_request_model(test_client, api_key, model="
|
18 |
request_data = {
|
19 |
"model": model,
|
20 |
"messages": [
|
@@ -79,4 +79,4 @@ def test_request_model(test_client, api_key, model="gpt-4o"):
|
|
79 |
assert response.status_code == 200
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
-
pytest.main(["-s", "test/
|
|
|
14 |
def api_key():
|
15 |
return os.environ.get("API")
|
16 |
|
17 |
+
def test_request_model(test_client, api_key, model="claude-3-5-sonnet-20240620"):
|
18 |
request_data = {
|
19 |
"model": model,
|
20 |
"messages": [
|
|
|
79 |
assert response.status_code == 200
|
80 |
|
81 |
if __name__ == "__main__":
|
82 |
+
pytest.main(["-s", "test/provider_test.py"])
|
utils.py
CHANGED
@@ -45,7 +45,7 @@ async def error_handling_wrapper(generator, status_code=200):
|
|
45 |
first_item_str = json.loads(first_item_str)
|
46 |
if isinstance(first_item_str, dict) and 'error' in first_item_str:
|
47 |
# 如果第一个 yield 的项是错误信息,抛出 HTTPException
|
48 |
-
raise HTTPException(status_code=status_code, detail=f"{first_item_str}"[:
|
49 |
|
50 |
# 如果不是错误,创建一个新的生成器,首先yield第一个项,然后yield剩余的项
|
51 |
async def new_generator():
|
|
|
45 |
first_item_str = json.loads(first_item_str)
|
46 |
if isinstance(first_item_str, dict) and 'error' in first_item_str:
|
47 |
# 如果第一个 yield 的项是错误信息,抛出 HTTPException
|
48 |
+
raise HTTPException(status_code=status_code, detail=f"{first_item_str}"[:200])
|
49 |
|
50 |
# 如果不是错误,创建一个新的生成器,首先yield第一个项,然后yield剩余的项
|
51 |
async def new_generator():
|