Update main.py
Browse files
main.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import Any, Dict, List, Optional
|
|
| 8 |
import httpx
|
| 9 |
import uvicorn
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
-
from fastapi import FastAPI, HTTPException
|
| 12 |
from pydantic import BaseModel
|
| 13 |
from starlette.responses import StreamingResponse
|
| 14 |
|
|
@@ -19,11 +19,10 @@ logger = logging.getLogger(__name__)
|
|
| 19 |
|
| 20 |
load_dotenv()
|
| 21 |
app = FastAPI()
|
| 22 |
-
APP_SECRET = os.getenv("APP_SECRET", "666")
|
| 23 |
ACCESS_TOKEN = os.getenv("SD_ACCESS_TOKEN", "")
|
| 24 |
headers = {
|
| 25 |
'authorization': f'Bearer {ACCESS_TOKEN}',
|
| 26 |
-
'user-agent': 'Mozilla/5.0
|
| 27 |
}
|
| 28 |
|
| 29 |
ALLOWED_MODELS = [
|
|
@@ -75,11 +74,12 @@ async def chat_completions(request: ChatRequest):
|
|
| 75 |
'prompt': "\n".join(
|
| 76 |
[f"{'User' if msg.role == 'user' else 'Assistant'}: {msg.content}" for msg in request.messages]
|
| 77 |
),
|
| 78 |
-
'stream':
|
| 79 |
'model': request.model,
|
| 80 |
}
|
| 81 |
|
| 82 |
-
logger.info(f"Sending request to external API with
|
|
|
|
| 83 |
|
| 84 |
async def generate():
|
| 85 |
async with httpx.AsyncClient() as client:
|
|
|
|
| 8 |
import httpx
|
| 9 |
import uvicorn
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
+
from fastapi import FastAPI, HTTPException
|
| 12 |
from pydantic import BaseModel
|
| 13 |
from starlette.responses import StreamingResponse
|
| 14 |
|
|
|
|
| 19 |
|
| 20 |
load_dotenv()
|
| 21 |
app = FastAPI()
|
|
|
|
| 22 |
ACCESS_TOKEN = os.getenv("SD_ACCESS_TOKEN", "")
|
| 23 |
headers = {
|
| 24 |
'authorization': f'Bearer {ACCESS_TOKEN}',
|
| 25 |
+
'user-agent': 'Mozilla/5.0',
|
| 26 |
}
|
| 27 |
|
| 28 |
ALLOWED_MODELS = [
|
|
|
|
| 74 |
'prompt': "\n".join(
|
| 75 |
[f"{'User' if msg.role == 'user' else 'Assistant'}: {msg.content}" for msg in request.messages]
|
| 76 |
),
|
| 77 |
+
'stream': request.stream,
|
| 78 |
'model': request.model,
|
| 79 |
}
|
| 80 |
|
| 81 |
+
logger.info(f"Sending request to external API with model: {request.model}")
|
| 82 |
+
logger.debug(f"Request payload: {json.dumps(json_data, indent=2)}")
|
| 83 |
|
| 84 |
async def generate():
|
| 85 |
async with httpx.AsyncClient() as client:
|