111
Browse files- routers/__pycache__/v1.cpython-311.pyc +0 -0
- routers/v1.py +6 -2
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
|
@@ -3,7 +3,7 @@ from fastapi import APIRouter, HTTPException, Request
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List, Optional
|
| 5 |
import random
|
| 6 |
-
import string
|
| 7 |
|
| 8 |
router = APIRouter()
|
| 9 |
|
|
@@ -47,9 +47,12 @@ async def chat_completions(chat_request: ChatCompletionRequest, request: Request
|
|
| 47 |
聊天完成 endpoint,调用 Gemini API
|
| 48 |
"""
|
| 49 |
headers = dict(request.headers)
|
|
|
|
| 50 |
print(headers)
|
| 51 |
gemini_api_url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" # 需要验证 URL 的正确性
|
| 52 |
auth_header = request.headers.get("Authorization")
|
|
|
|
|
|
|
| 53 |
headers = {"Content-Type": "application/json"}
|
| 54 |
if auth_header:
|
| 55 |
headers["Authorization"] = auth_header
|
|
@@ -60,7 +63,8 @@ async def chat_completions(chat_request: ChatCompletionRequest, request: Request
|
|
| 60 |
|
| 61 |
# 将 Gemini API 的响应转换为 ChatCompletionResponse
|
| 62 |
gemini_response = response.json()
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
chat_completion_response = ChatCompletionResponse(
|
| 66 |
id=generate_chatcmpl_id(),
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from typing import List, Optional
|
| 5 |
import random
|
| 6 |
+
import string,json
|
| 7 |
|
| 8 |
router = APIRouter()
|
| 9 |
|
|
|
|
| 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 |
+
|
| 55 |
+
# 重写 设置请求头
|
| 56 |
headers = {"Content-Type": "application/json"}
|
| 57 |
if auth_header:
|
| 58 |
headers["Authorization"] = auth_header
|
|
|
|
| 63 |
|
| 64 |
# 将 Gemini API 的响应转换为 ChatCompletionResponse
|
| 65 |
gemini_response = response.json()
|
| 66 |
+
formatted_response = json.dumps(gemini_response, indent=4, ensure_ascii=False)
|
| 67 |
+
print(f"\n\n\nGemini API response: {formatted_response}") # 打印 Gemini API 的响应
|
| 68 |
|
| 69 |
chat_completion_response = ChatCompletionResponse(
|
| 70 |
id=generate_chatcmpl_id(),
|