dhruv575 commited on
Commit ·
a9f612f
1
Parent(s): 19f11a0
Rewrote OpenAI
Browse files- llm_client.py +12 -1
- requirements.txt +1 -0
llm_client.py
CHANGED
|
@@ -6,6 +6,7 @@ Handles communication with various LLM API providers.
|
|
| 6 |
import os
|
| 7 |
from typing import Optional, Dict, Any
|
| 8 |
from openai import OpenAI
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
class LLMClient:
|
|
@@ -37,7 +38,17 @@ class OpenAIClient(LLMClient):
|
|
| 37 |
api_key = os.getenv('OPENAI_KEY')
|
| 38 |
if not api_key:
|
| 39 |
raise ValueError("OPENAI_KEY environment variable is not set")
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def query(self, prompt: str, model: str, **kwargs) -> Dict[str, Any]:
|
| 43 |
"""
|
|
|
|
| 6 |
import os
|
| 7 |
from typing import Optional, Dict, Any
|
| 8 |
from openai import OpenAI
|
| 9 |
+
import httpx
|
| 10 |
|
| 11 |
|
| 12 |
class LLMClient:
|
|
|
|
| 38 |
api_key = os.getenv('OPENAI_KEY')
|
| 39 |
if not api_key:
|
| 40 |
raise ValueError("OPENAI_KEY environment variable is not set")
|
| 41 |
+
|
| 42 |
+
# Create httpx client with explicit configuration
|
| 43 |
+
# Using a basic client to avoid any proxy/environment variable issues
|
| 44 |
+
http_client = httpx.Client(timeout=60.0)
|
| 45 |
+
|
| 46 |
+
# Initialize OpenAI client with explicit http_client and api_key
|
| 47 |
+
# Passing http_client explicitly avoids the 'proxies' parameter error
|
| 48 |
+
self.client = OpenAI(
|
| 49 |
+
api_key=api_key,
|
| 50 |
+
http_client=http_client
|
| 51 |
+
)
|
| 52 |
|
| 53 |
def query(self, prompt: str, model: str, **kwargs) -> Dict[str, Any]:
|
| 54 |
"""
|
requirements.txt
CHANGED
|
@@ -3,3 +3,4 @@ flask-cors==4.0.0
|
|
| 3 |
psycopg2-binary==2.9.9
|
| 4 |
python-dotenv==1.0.0
|
| 5 |
openai==1.12.0
|
|
|
|
|
|
| 3 |
psycopg2-binary==2.9.9
|
| 4 |
python-dotenv==1.0.0
|
| 5 |
openai==1.12.0
|
| 6 |
+
httpx>=0.25.0
|