Spaces:
Build error
Build error
fix env
Browse files
server.py
CHANGED
|
@@ -6,7 +6,13 @@ import json
|
|
| 6 |
from classifiers.llm import LLMClassifier
|
| 7 |
from litellm import completion
|
| 8 |
import asyncio
|
| 9 |
-
from client import get_client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
# Configure CORS
|
|
@@ -18,7 +24,16 @@ app.add_middleware(
|
|
| 18 |
allow_headers=["*"],
|
| 19 |
)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
client = get_client()
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Initialize the LLM classifier
|
| 24 |
classifier = LLMClassifier(client=client, model="gpt-3.5-turbo")
|
|
|
|
| 6 |
from classifiers.llm import LLMClassifier
|
| 7 |
from litellm import completion
|
| 8 |
import asyncio
|
| 9 |
+
from client import get_client, initialize_client
|
| 10 |
+
import os
|
| 11 |
+
from dotenv import load_dotenv
|
| 12 |
+
|
| 13 |
+
# Load environment variables
|
| 14 |
+
load_dotenv()
|
| 15 |
+
|
| 16 |
app = FastAPI()
|
| 17 |
|
| 18 |
# Configure CORS
|
|
|
|
| 24 |
allow_headers=["*"],
|
| 25 |
)
|
| 26 |
|
| 27 |
+
# Initialize client with API key from environment
|
| 28 |
+
api_key = os.environ.get("OPENAI_API_KEY")
|
| 29 |
+
if api_key:
|
| 30 |
+
success, message = initialize_client(api_key)
|
| 31 |
+
if not success:
|
| 32 |
+
raise RuntimeError(f"Failed to initialize OpenAI client: {message}")
|
| 33 |
+
|
| 34 |
client = get_client()
|
| 35 |
+
if not client:
|
| 36 |
+
raise RuntimeError("OpenAI client not initialized. Please set OPENAI_API_KEY environment variable.")
|
| 37 |
|
| 38 |
# Initialize the LLM classifier
|
| 39 |
classifier = LLMClassifier(client=client, model="gpt-3.5-turbo")
|