tmp
Browse files
app.py
CHANGED
@@ -13,9 +13,18 @@ if not hasattr(collections, "MutableMapping"):
|
|
13 |
collections.MutableMapping = collections.abc.MutableMapping
|
14 |
import httpx
|
15 |
import logging
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
logger = logging.getLogger(__name__)
|
18 |
|
|
|
|
|
|
|
19 |
app = FastAPI()
|
20 |
|
21 |
from starlette.middleware.cors import CORSMiddleware
|
@@ -51,7 +60,26 @@ async def unify_chat_completions(request: Request, body: dict = Body(...)):
|
|
51 |
"Content-Type": "application/json"
|
52 |
}
|
53 |
endpoint = "https://api.unify.ai/v0/chat/completions"
|
54 |
-
logger.debug(body)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
async def stream_response():
|
56 |
async with httpx.AsyncClient(timeout=600) as client:
|
57 |
async with client.stream("POST", endpoint, json=body, headers=headers) as response:
|
|
|
13 |
collections.MutableMapping = collections.abc.MutableMapping
|
14 |
import httpx
|
15 |
import logging
|
16 |
+
import os
|
17 |
|
18 |
+
# ロギング設定を追加
|
19 |
+
logging.basicConfig(
|
20 |
+
level=os.getenv('LOG_LEVEL', 'INFO'),
|
21 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
22 |
+
)
|
23 |
logger = logging.getLogger(__name__)
|
24 |
|
25 |
+
# HTTPXのログも有効化する場合は以下も追加
|
26 |
+
logging.getLogger("httpx").setLevel(logging.DEBUG)
|
27 |
+
|
28 |
app = FastAPI()
|
29 |
|
30 |
from starlette.middleware.cors import CORSMiddleware
|
|
|
60 |
"Content-Type": "application/json"
|
61 |
}
|
62 |
endpoint = "https://api.unify.ai/v0/chat/completions"
|
63 |
+
logger.debug(f"リクエストボディ: {body}")
|
64 |
+
logger.debug(f"リクエストヘッダー: {headers}")
|
65 |
+
|
66 |
+
# streamがFalseの場合は通常のレスポンスを返す
|
67 |
+
if not body.get("stream", True):
|
68 |
+
async with httpx.AsyncClient(timeout=600) as client:
|
69 |
+
logger.debug(f"非ストリーミングモードでリクエスト送信: {endpoint}")
|
70 |
+
response = await client.post(endpoint, json=body, headers=headers)
|
71 |
+
logger.debug(f"ステータスコード: {response.status_code}")
|
72 |
+
logger.debug(f"レスポンスヘッダー: {response.headers}")
|
73 |
+
|
74 |
+
if response.status_code != 200:
|
75 |
+
logger.error(f"エラーレスポンス: {response.text}")
|
76 |
+
raise HTTPException(status_code=response.status_code, detail=response.text)
|
77 |
+
|
78 |
+
response_json = response.json()
|
79 |
+
logger.debug(f"レスポンスボディ: {response_json}")
|
80 |
+
return ORJSONResponse(response_json)
|
81 |
+
|
82 |
+
# streamがTrueの場合は既存のストリーミング処理
|
83 |
async def stream_response():
|
84 |
async with httpx.AsyncClient(timeout=600) as client:
|
85 |
async with client.stream("POST", endpoint, json=body, headers=headers) as response:
|
gemini.js
CHANGED
@@ -342,7 +342,7 @@ function loadFromUserStorage() {
|
|
342 |
});
|
343 |
getModelList().then(models => {
|
344 |
const endpointSelect = document.getElementById('endpointSelect');
|
345 |
-
endpointSelect.innerHTML = '';
|
346 |
models.forEach(model => {
|
347 |
const option = document.createElement('option');
|
348 |
option.value = model.name;
|
|
|
342 |
});
|
343 |
getModelList().then(models => {
|
344 |
const endpointSelect = document.getElementById('endpointSelect');
|
345 |
+
//endpointSelect.innerHTML = '';
|
346 |
models.forEach(model => {
|
347 |
const option = document.createElement('option');
|
348 |
option.value = model.name;
|