Spaces:
Sleeping
Sleeping
eeshwar143 commited on
Commit ·
522cbe5
1
Parent(s): 44db7dd
Add local .env loading for inference
Browse files- .gitignore +1 -0
- inference.py +21 -0
.gitignore
CHANGED
|
@@ -2,5 +2,6 @@
|
|
| 2 |
.docker/
|
| 3 |
__pycache__/
|
| 4 |
.pytest_cache/
|
|
|
|
| 5 |
inference_results.json
|
| 6 |
*.egg-info/
|
|
|
|
| 2 |
.docker/
|
| 3 |
__pycache__/
|
| 4 |
.pytest_cache/
|
| 5 |
+
.env
|
| 6 |
inference_results.json
|
| 7 |
*.egg-info/
|
inference.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
| 3 |
import asyncio
|
| 4 |
import json
|
| 5 |
import os
|
|
|
|
| 6 |
from typing import Any, List
|
| 7 |
|
| 8 |
try:
|
|
@@ -16,6 +17,26 @@ from support_queue_env.client import SupportQueueEnv
|
|
| 16 |
from support_queue_env.models import TaskCard, SupportQueueAction, SupportQueueObservation
|
| 17 |
from support_queue_env.tasks import TASKS
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://api.openai.com/v1")
|
| 20 |
MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4o-mini")
|
| 21 |
API_KEY = os.getenv("API_KEY")
|
|
|
|
| 3 |
import asyncio
|
| 4 |
import json
|
| 5 |
import os
|
| 6 |
+
from pathlib import Path
|
| 7 |
from typing import Any, List
|
| 8 |
|
| 9 |
try:
|
|
|
|
| 17 |
from support_queue_env.models import TaskCard, SupportQueueAction, SupportQueueObservation
|
| 18 |
from support_queue_env.tasks import TASKS
|
| 19 |
|
| 20 |
+
|
| 21 |
+
def load_dotenv_file(path: str = ".env") -> None:
|
| 22 |
+
env_path = Path(path)
|
| 23 |
+
if not env_path.exists():
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
for raw_line in env_path.read_text(encoding="utf-8").splitlines():
|
| 27 |
+
line = raw_line.strip()
|
| 28 |
+
if not line or line.startswith("#") or "=" not in line:
|
| 29 |
+
continue
|
| 30 |
+
|
| 31 |
+
key, value = line.split("=", 1)
|
| 32 |
+
key = key.strip()
|
| 33 |
+
value = value.strip().strip('"').strip("'")
|
| 34 |
+
if key and key not in os.environ:
|
| 35 |
+
os.environ[key] = value
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
load_dotenv_file()
|
| 39 |
+
|
| 40 |
API_BASE_URL = os.getenv("API_BASE_URL", "https://api.openai.com/v1")
|
| 41 |
MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4o-mini")
|
| 42 |
API_KEY = os.getenv("API_KEY")
|