Joshua Wehr commited on
Commit ·
fdc4237
1
Parent(s): a7b9e08
Switched to private key
Browse files- app/__main__.py +14 -10
- app_gradio.py +17 -11
app/__main__.py
CHANGED
|
@@ -10,6 +10,7 @@ Architecture:
|
|
| 10 |
"""
|
| 11 |
|
| 12 |
import asyncio
|
|
|
|
| 13 |
import sys
|
| 14 |
from pathlib import Path
|
| 15 |
|
|
@@ -59,22 +60,25 @@ async def chat_loop(settings) -> None:
|
|
| 59 |
|
| 60 |
# Initialise LLM provider (Azure OpenAI or standard OpenAI)
|
| 61 |
try:
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
llm_provider = AzureOpenAIProvider(
|
| 64 |
-
endpoint=
|
| 65 |
-
api_key=
|
| 66 |
deployment_name=settings.azure_openai.deployment_name,
|
| 67 |
api_version=settings.azure_openai.api_version,
|
| 68 |
temperature=settings.azure_openai.temperature,
|
| 69 |
max_tokens=settings.azure_openai.max_tokens,
|
| 70 |
)
|
| 71 |
-
elif getattr(settings, "openai_api_key", ""):
|
| 72 |
-
llm_provider = OpenAILLMProvider(
|
| 73 |
-
api_key=settings.openai_api_key,
|
| 74 |
-
model_name=settings.azure_openai.deployment_name,
|
| 75 |
-
max_tokens=settings.azure_openai.max_tokens,
|
| 76 |
-
temperature=settings.azure_openai.temperature,
|
| 77 |
-
)
|
| 78 |
else:
|
| 79 |
print("\n❌ No API key configured. Set OPENAI_API_KEY or AZURE_OPENAI_API_KEY in .env")
|
| 80 |
return
|
|
|
|
| 10 |
"""
|
| 11 |
|
| 12 |
import asyncio
|
| 13 |
+
import os
|
| 14 |
import sys
|
| 15 |
from pathlib import Path
|
| 16 |
|
|
|
|
| 60 |
|
| 61 |
# Initialise LLM provider (Azure OpenAI or standard OpenAI)
|
| 62 |
try:
|
| 63 |
+
openai_key = (getattr(settings, "openai_api_key", "") or "").strip()
|
| 64 |
+
azure_key = (settings.azure_openai.api_key or "").strip()
|
| 65 |
+
azure_endpoint = (settings.azure_openai.endpoint or "").strip()
|
| 66 |
+
if openai_key:
|
| 67 |
+
llm_provider = OpenAILLMProvider(
|
| 68 |
+
api_key=openai_key,
|
| 69 |
+
model_name=os.getenv("OPENAI_MODEL", "gpt-4o-mini").strip(),
|
| 70 |
+
max_tokens=settings.azure_openai.max_tokens,
|
| 71 |
+
temperature=settings.azure_openai.temperature,
|
| 72 |
+
)
|
| 73 |
+
elif azure_endpoint and azure_key:
|
| 74 |
llm_provider = AzureOpenAIProvider(
|
| 75 |
+
endpoint=azure_endpoint,
|
| 76 |
+
api_key=azure_key,
|
| 77 |
deployment_name=settings.azure_openai.deployment_name,
|
| 78 |
api_version=settings.azure_openai.api_version,
|
| 79 |
temperature=settings.azure_openai.temperature,
|
| 80 |
max_tokens=settings.azure_openai.max_tokens,
|
| 81 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
else:
|
| 83 |
print("\n❌ No API key configured. Set OPENAI_API_KEY or AZURE_OPENAI_API_KEY in .env")
|
| 84 |
return
|
app_gradio.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import sys
|
| 2 |
from pathlib import Path
|
| 3 |
|
|
@@ -12,24 +13,29 @@ from config.settings import get_settings
|
|
| 12 |
|
| 13 |
def _build_orchestrator() -> Orchestrator:
|
| 14 |
settings = get_settings()
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
provider = AzureOpenAIProvider(
|
| 17 |
-
endpoint=
|
| 18 |
-
api_key=
|
| 19 |
deployment_name=settings.azure_openai.deployment_name,
|
| 20 |
api_version=settings.azure_openai.api_version,
|
| 21 |
temperature=settings.azure_openai.temperature,
|
| 22 |
max_tokens=settings.azure_openai.max_tokens,
|
| 23 |
)
|
| 24 |
-
elif settings.openai_api_key:
|
| 25 |
-
provider = OpenAILLMProvider(
|
| 26 |
-
api_key=settings.openai_api_key,
|
| 27 |
-
model_name=settings.azure_openai.deployment_name or "gpt-4o-mini",
|
| 28 |
-
max_tokens=settings.azure_openai.max_tokens,
|
| 29 |
-
temperature=settings.azure_openai.temperature,
|
| 30 |
-
)
|
| 31 |
else:
|
| 32 |
-
raise RuntimeError("No LLM API key configured. Set
|
| 33 |
return Orchestrator(provider, settings)
|
| 34 |
|
| 35 |
|
|
|
|
| 1 |
+
import os
|
| 2 |
import sys
|
| 3 |
from pathlib import Path
|
| 4 |
|
|
|
|
| 13 |
|
| 14 |
def _build_orchestrator() -> Orchestrator:
|
| 15 |
settings = get_settings()
|
| 16 |
+
# Prefer the plain OpenAI key; strip whitespace since pasted secrets often
|
| 17 |
+
# carry a trailing newline, which httpx rejects as a "Connection error".
|
| 18 |
+
openai_key = (settings.openai_api_key or "").strip()
|
| 19 |
+
azure_key = (settings.azure_openai.api_key or "").strip()
|
| 20 |
+
azure_endpoint = (settings.azure_openai.endpoint or "").strip()
|
| 21 |
+
if openai_key:
|
| 22 |
+
provider = OpenAILLMProvider(
|
| 23 |
+
api_key=openai_key,
|
| 24 |
+
model_name=os.getenv("OPENAI_MODEL", "gpt-4o-mini").strip(),
|
| 25 |
+
max_tokens=settings.azure_openai.max_tokens,
|
| 26 |
+
temperature=settings.azure_openai.temperature,
|
| 27 |
+
)
|
| 28 |
+
elif azure_endpoint and azure_key:
|
| 29 |
provider = AzureOpenAIProvider(
|
| 30 |
+
endpoint=azure_endpoint,
|
| 31 |
+
api_key=azure_key,
|
| 32 |
deployment_name=settings.azure_openai.deployment_name,
|
| 33 |
api_version=settings.azure_openai.api_version,
|
| 34 |
temperature=settings.azure_openai.temperature,
|
| 35 |
max_tokens=settings.azure_openai.max_tokens,
|
| 36 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
else:
|
| 38 |
+
raise RuntimeError("No LLM API key configured. Set OPENAI_API_KEY or AZURE_OPENAI_API_KEY.")
|
| 39 |
return Orchestrator(provider, settings)
|
| 40 |
|
| 41 |
|