111
Browse files- routers/__pycache__/v1.cpython-311.pyc +0 -0
- routers/v1.py +6 -1
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
|
@@ -47,8 +47,11 @@ async def chat_completions(chat_request: ChatCompletionRequest, request: Request
|
|
| 47 |
聊天完成 endpoint,调用 Gemini API
|
| 48 |
"""
|
| 49 |
headers = dict(request.headers)
|
|
|
|
| 50 |
print('\n\n\n接收到前端发过来的头信息')
|
| 51 |
print(headers)
|
|
|
|
|
|
|
| 52 |
gemini_api_url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" # 需要验证 URL 的正确性
|
| 53 |
auth_header = request.headers.get("Authorization")
|
| 54 |
|
|
@@ -58,7 +61,9 @@ async def chat_completions(chat_request: ChatCompletionRequest, request: Request
|
|
| 58 |
headers["Authorization"] = auth_header
|
| 59 |
|
| 60 |
try:
|
| 61 |
-
response = requests.post(gemini_api_url, headers=headers, json=chat_request.model_dump())
|
|
|
|
|
|
|
| 62 |
response.raise_for_status() # 检查请求是否成功
|
| 63 |
|
| 64 |
# 将 Gemini API 的响应转换为 ChatCompletionResponse
|
|
|
|
| 47 |
聊天完成 endpoint,调用 Gemini API
|
| 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")
|
| 57 |
|
|
|
|
| 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
|