Spaces:
Runtime error
Runtime error
vhr1007
commited on
Commit
·
b9ffe6a
1
Parent(s):
88bbe7d
azure_open_ai
Browse files- config.py +2 -1
- services/openai_service.py +21 -4
config.py
CHANGED
|
@@ -5,4 +5,5 @@ QDRANT_URL = os.getenv('QDRANT_URL')
|
|
| 5 |
QDRANT_ACCESS_TOKEN = os.getenv('QDRANT_ACCESS_TOKEN')
|
| 6 |
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
|
| 7 |
JWKS_URL = os.getenv('JWKS_URL')
|
| 8 |
-
X_API_KEY = os.getenv('X_API_KEY')
|
|
|
|
|
|
| 5 |
QDRANT_ACCESS_TOKEN = os.getenv('QDRANT_ACCESS_TOKEN')
|
| 6 |
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
|
| 7 |
JWKS_URL = os.getenv('JWKS_URL')
|
| 8 |
+
X_API_KEY = os.getenv('X_API_KEY')
|
| 9 |
+
AZURE_OPENAI_KEY = os.getenv('AZURE_OPENAI_KEY')
|
services/openai_service.py
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
|
|
| 1 |
import logging
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
|
|
|
| 4 |
from openai import OpenAIError, RateLimitError
|
| 5 |
-
from config import OPENAI_API_KEY
|
| 6 |
|
| 7 |
# Initialize the OpenAI client with the API key from the environment variable
|
| 8 |
#api_key = os.getenv('OPENAI_API_KEY')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def generate_rag_response(json_output, user_query):
|
| 13 |
logging.info("Generating RAG response")
|
|
@@ -28,8 +39,9 @@ def generate_rag_response(json_output, user_query):
|
|
| 28 |
# Create a chat completion request
|
| 29 |
chat_completion = client.chat.completions.create(
|
| 30 |
messages=main_prompt,
|
| 31 |
-
model="gpt-
|
| 32 |
-
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
# Log the response from the model
|
|
@@ -46,3 +58,8 @@ def generate_rag_response(json_output, user_query):
|
|
| 46 |
except Exception as e:
|
| 47 |
logging.error(f"Unexpected error: {e}")
|
| 48 |
return None, str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
import logging
|
| 3 |
import os
|
| 4 |
from openai import OpenAI
|
| 5 |
+
from openai import AzureOpenAI
|
| 6 |
from openai import OpenAIError, RateLimitError
|
| 7 |
+
from config import OPENAI_API_KEY, AZURE_OPENAI_KEY
|
| 8 |
|
| 9 |
# Initialize the OpenAI client with the API key from the environment variable
|
| 10 |
#api_key = os.getenv('OPENAI_API_KEY')
|
| 11 |
+
# client = OpenAI(api_key=OPENAI_API_KEY)
|
| 12 |
+
|
| 13 |
+
AZURE_OPENAI_ENDPOINT = os.getenv('AZURE_OPENAI_ENDPOINT')
|
| 14 |
+
AZURE_API_VERSION = "2024-02-15-preview" # API version for Azure OpenAI
|
| 15 |
|
| 16 |
+
# Initialize the Azure OpenAI client with the endpoint and API key
|
| 17 |
+
client = AzureOpenAI(
|
| 18 |
+
azure_endpoint=AZURE_OPENAI_ENDPOINT,
|
| 19 |
+
api_key=AZURE_OPENAI_KEY,
|
| 20 |
+
api_version=AZURE_API_VERSION
|
| 21 |
+
)
|
| 22 |
|
| 23 |
def generate_rag_response(json_output, user_query):
|
| 24 |
logging.info("Generating RAG response")
|
|
|
|
| 39 |
# Create a chat completion request
|
| 40 |
chat_completion = client.chat.completions.create(
|
| 41 |
messages=main_prompt,
|
| 42 |
+
model="gpt-35-turbo", # Use the gpt-4o-mini model
|
| 43 |
+
max_tokens=486, # Limit the maximum number of tokens in the response
|
| 44 |
+
temperature=1
|
| 45 |
)
|
| 46 |
|
| 47 |
# Log the response from the model
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
logging.error(f"Unexpected error: {e}")
|
| 60 |
return None, str(e)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|