111
Browse files- routers/__pycache__/v1.cpython-311.pyc +0 -0
- routers/v1.py +6 -6
routers/__pycache__/v1.cpython-311.pyc
CHANGED
|
Binary files a/routers/__pycache__/v1.cpython-311.pyc and b/routers/__pycache__/v1.cpython-311.pyc differ
|
|
|
routers/v1.py
CHANGED
|
@@ -48,9 +48,9 @@ async def chat_completions(chat_request: ChatCompletionRequest, request: Request
|
|
| 48 |
"""
|
| 49 |
headers = dict(request.headers)
|
| 50 |
body = await request.body()
|
| 51 |
-
print('
|
| 52 |
print(headers)
|
| 53 |
-
print('
|
| 54 |
print(body)
|
| 55 |
gemini_api_url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" # 需要验证 URL 的正确性
|
| 56 |
auth_header = request.headers.get("Authorization")
|
|
@@ -61,15 +61,15 @@ async def chat_completions(chat_request: ChatCompletionRequest, request: Request
|
|
| 61 |
headers["Authorization"] = auth_header
|
| 62 |
|
| 63 |
try:
|
| 64 |
-
|
| 65 |
-
import json
|
| 66 |
-
response = requests.post(gemini_api_url, headers=headers, json=json.loads(body))
|
| 67 |
response.raise_for_status() # 检查请求是否成功
|
| 68 |
|
| 69 |
# 将 Gemini API 的响应转换为 ChatCompletionResponse
|
| 70 |
gemini_response = response.json()
|
| 71 |
formatted_response = json.dumps(gemini_response, indent=4, ensure_ascii=False)
|
| 72 |
-
print(f"
|
| 73 |
|
| 74 |
chat_completion_response = ChatCompletionResponse(
|
| 75 |
id=generate_chatcmpl_id(),
|
|
|
|
| 48 |
"""
|
| 49 |
headers = dict(request.headers)
|
| 50 |
body = await request.body()
|
| 51 |
+
print('\\n\\n\\n接收到前端发过来的头信息')
|
| 52 |
print(headers)
|
| 53 |
+
print('\\n\\n\\n接收到前端发过来的body信息')
|
| 54 |
print(body)
|
| 55 |
gemini_api_url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" # 需要验证 URL 的正确性
|
| 56 |
auth_header = request.headers.get("Authorization")
|
|
|
|
| 61 |
headers["Authorization"] = auth_header
|
| 62 |
|
| 63 |
try:
|
| 64 |
+
response = requests.post(gemini_api_url, headers=headers, json=chat_request.model_dump())
|
| 65 |
+
#import json
|
| 66 |
+
#response = requests.post(gemini_api_url, headers=headers, json=json.loads(body))
|
| 67 |
response.raise_for_status() # 检查请求是否成功
|
| 68 |
|
| 69 |
# 将 Gemini API 的响应转换为 ChatCompletionResponse
|
| 70 |
gemini_response = response.json()
|
| 71 |
formatted_response = json.dumps(gemini_response, indent=4, ensure_ascii=False)
|
| 72 |
+
print(f"\\n\\n\\nGemini API response: {formatted_response}") # 打印 Gemini API 的响应
|
| 73 |
|
| 74 |
chat_completion_response = ChatCompletionResponse(
|
| 75 |
id=generate_chatcmpl_id(),
|