Spaces:
Running
Running
Update document_generator.py
Browse files- document_generator.py +34 -45
document_generator.py
CHANGED
|
@@ -153,6 +153,40 @@ class LLMObservabilityManager:
|
|
| 153 |
return self.get_observations()
|
| 154 |
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
# aiclient.py
|
| 157 |
|
| 158 |
class AIClient:
|
|
@@ -232,40 +266,6 @@ class AIClient:
|
|
| 232 |
return response.choices[0].message.content
|
| 233 |
|
| 234 |
|
| 235 |
-
# File: app.py
|
| 236 |
-
import os
|
| 237 |
-
import json
|
| 238 |
-
import re
|
| 239 |
-
import asyncio
|
| 240 |
-
import time
|
| 241 |
-
from typing import List, Dict, Optional, Any, Callable
|
| 242 |
-
from openai import OpenAI
|
| 243 |
-
import logging
|
| 244 |
-
import functools
|
| 245 |
-
from fastapi import APIRouter, HTTPException, Request
|
| 246 |
-
from fastapi.responses import StreamingResponse
|
| 247 |
-
from pydantic import BaseModel
|
| 248 |
-
from fastapi_cache.decorator import cache
|
| 249 |
-
import psycopg2
|
| 250 |
-
from datetime import datetime
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 254 |
-
logger = logging.getLogger(__name__)
|
| 255 |
-
|
| 256 |
-
def log_execution(func: Callable) -> Callable:
|
| 257 |
-
@functools.wraps(func)
|
| 258 |
-
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
| 259 |
-
logger.info(f"Executing {func.__name__}")
|
| 260 |
-
try:
|
| 261 |
-
result = func(*args, **kwargs)
|
| 262 |
-
logger.info(f"{func.__name__} completed successfully")
|
| 263 |
-
return result
|
| 264 |
-
except Exception as e:
|
| 265 |
-
logger.error(f"Error in {func.__name__}: {e}")
|
| 266 |
-
raise
|
| 267 |
-
return wrapper
|
| 268 |
-
|
| 269 |
class DatabaseManager:
|
| 270 |
"""Manages database operations."""
|
| 271 |
|
|
@@ -287,17 +287,6 @@ class DatabaseManager:
|
|
| 287 |
VALUES (%s, %s, %s);
|
| 288 |
"""
|
| 289 |
cur.execute(insert_query, (user_id, user_query, response))
|
| 290 |
-
|
| 291 |
-
def log_execution(func):
|
| 292 |
-
@wraps(func)
|
| 293 |
-
def wrapper(*args, **kwargs):
|
| 294 |
-
start_time = time.time()
|
| 295 |
-
result = func(*args, **kwargs)
|
| 296 |
-
end_time = time.time()
|
| 297 |
-
print(f"{func.__name__} executed in {end_time - start_time:.2f} seconds")
|
| 298 |
-
return result
|
| 299 |
-
return wrapper
|
| 300 |
-
|
| 301 |
|
| 302 |
class DocumentGenerator:
|
| 303 |
def __init__(self, ai_client: AIClient):
|
|
|
|
| 153 |
return self.get_observations()
|
| 154 |
|
| 155 |
|
| 156 |
+
# File: app.py
|
| 157 |
+
import os
|
| 158 |
+
import json
|
| 159 |
+
import re
|
| 160 |
+
import asyncio
|
| 161 |
+
import time
|
| 162 |
+
from typing import List, Dict, Optional, Any, Callable
|
| 163 |
+
from openai import OpenAI
|
| 164 |
+
import logging
|
| 165 |
+
import functools
|
| 166 |
+
from fastapi import APIRouter, HTTPException, Request
|
| 167 |
+
from fastapi.responses import StreamingResponse
|
| 168 |
+
from pydantic import BaseModel
|
| 169 |
+
from fastapi_cache.decorator import cache
|
| 170 |
+
import psycopg2
|
| 171 |
+
from datetime import datetime
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 175 |
+
logger = logging.getLogger(__name__)
|
| 176 |
+
|
| 177 |
+
def log_execution(func: Callable) -> Callable:
|
| 178 |
+
@functools.wraps(func)
|
| 179 |
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
| 180 |
+
logger.info(f"Executing {func.__name__}")
|
| 181 |
+
try:
|
| 182 |
+
result = func(*args, **kwargs)
|
| 183 |
+
logger.info(f"{func.__name__} completed successfully")
|
| 184 |
+
return result
|
| 185 |
+
except Exception as e:
|
| 186 |
+
logger.error(f"Error in {func.__name__}: {e}")
|
| 187 |
+
raise
|
| 188 |
+
return wrapper
|
| 189 |
+
|
| 190 |
# aiclient.py
|
| 191 |
|
| 192 |
class AIClient:
|
|
|
|
| 266 |
return response.choices[0].message.content
|
| 267 |
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
class DatabaseManager:
|
| 270 |
"""Manages database operations."""
|
| 271 |
|
|
|
|
| 287 |
VALUES (%s, %s, %s);
|
| 288 |
"""
|
| 289 |
cur.execute(insert_query, (user_id, user_query, response))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
class DocumentGenerator:
|
| 292 |
def __init__(self, ai_client: AIClient):
|