Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,34 @@ import aiohttp
|
|
15 |
import openai
|
16 |
import gradio as gr
|
17 |
from tenacity import retry, stop_after_attempt, wait_exponential
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Type variables
|
20 |
T = TypeVar('T')
|
|
|
15 |
import openai
|
16 |
import gradio as gr
|
17 |
from tenacity import retry, stop_after_attempt, wait_exponential
|
18 |
+
from pathlib import Path # β
Fix 'Path' not defined error
|
19 |
+
from dataclasses import dataclass # β
Fix 'dataclass' not defined error
|
20 |
+
import os
|
21 |
+
import json
|
22 |
+
import logging
|
23 |
+
import asyncio
|
24 |
+
from typing import List, Dict, Tuple, Any, Optional
|
25 |
+
|
26 |
+
# β
Fix 'Config' self-referencing error by using a string in type hint
|
27 |
+
@dataclass
|
28 |
+
class Config:
|
29 |
+
"""Application configuration settings."""
|
30 |
+
|
31 |
+
SYSTEM_PROMPT: str = "You are an AI-powered blockchain assistant."
|
32 |
+
OPENAI_MODEL: str = "gpt-4o-mini"
|
33 |
+
MAX_TOKENS: int = 4000
|
34 |
+
TEMPERATURE: float = 0.7
|
35 |
+
|
36 |
+
@classmethod
|
37 |
+
def load(cls, config_path: str | Path) -> "Config": # β
Fix self-referencing error
|
38 |
+
"""Load configuration from a JSON file."""
|
39 |
+
try:
|
40 |
+
with open(config_path) as f:
|
41 |
+
config_data = json.load(f)
|
42 |
+
return cls(**config_data)
|
43 |
+
except Exception as e:
|
44 |
+
logging.error(f"Error loading config: {e}")
|
45 |
+
return cls()
|
46 |
|
47 |
# Type variables
|
48 |
T = TypeVar('T')
|