Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -25,6 +25,17 @@ BASE_URL = os.getenv("BASE_URL", "https://generativelanguage.googleapis.com/v1be
|
|
| 25 |
EXPECTED_API_KEY = os.getenv("API_HUGGINGFACE")
|
| 26 |
API_KEY_NAME = "Authorization"
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
| 29 |
app = FastAPI(title="OpenAI-SDK-compatible API", version="1.0.0", description="Un wrapper FastAPI compatibile con le specifiche dell'API OpenAI.")
|
| 30 |
app.add_middleware(
|
|
@@ -94,17 +105,7 @@ def read_general():
|
|
| 94 |
async def health_check():
|
| 95 |
return {"message": "success"}
|
| 96 |
|
| 97 |
-
class Message(BaseModel):
|
| 98 |
-
role: str
|
| 99 |
-
content: str
|
| 100 |
-
|
| 101 |
# ---------------------------------- Generazione Testo ---------------------------------------
|
| 102 |
-
class ChatCompletionRequest(BaseModel):
|
| 103 |
-
model: str = "gemini-2.0-flash"
|
| 104 |
-
messages: List[Message]
|
| 105 |
-
max_tokens: Optional[int] = 8196
|
| 106 |
-
temperature: Optional[float] = 0.8
|
| 107 |
-
stream: Optional[bool] = False
|
| 108 |
|
| 109 |
@app.post("/v1/chat/completions", dependencies=[Depends(verify_api_key)])
|
| 110 |
async def chat_completions(req: ChatCompletionRequest):
|
|
|
|
| 25 |
EXPECTED_API_KEY = os.getenv("API_HUGGINGFACE")
|
| 26 |
API_KEY_NAME = "Authorization"
|
| 27 |
|
| 28 |
+
class Message(BaseModel):
|
| 29 |
+
role: str
|
| 30 |
+
content: str
|
| 31 |
+
|
| 32 |
+
class ChatCompletionRequest(BaseModel):
|
| 33 |
+
model: str = "gemini-2.0-flash"
|
| 34 |
+
messages: List[Message]
|
| 35 |
+
max_tokens: Optional[int] = 8196
|
| 36 |
+
temperature: Optional[float] = 0.8
|
| 37 |
+
stream: Optional[bool] = False
|
| 38 |
+
|
| 39 |
api_key_header = APIKeyHeader(name=API_KEY_NAME, auto_error=False)
|
| 40 |
app = FastAPI(title="OpenAI-SDK-compatible API", version="1.0.0", description="Un wrapper FastAPI compatibile con le specifiche dell'API OpenAI.")
|
| 41 |
app.add_middleware(
|
|
|
|
| 105 |
async def health_check():
|
| 106 |
return {"message": "success"}
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
# ---------------------------------- Generazione Testo ---------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
@app.post("/v1/chat/completions", dependencies=[Depends(verify_api_key)])
|
| 111 |
async def chat_completions(req: ChatCompletionRequest):
|