Spaces:
Sleeping
Sleeping
Commit
Β·
3eeed2d
1
Parent(s):
8a1135c
Fix OPIK configuration: make COMET_PROJECT optional
Browse files
src/second_brain_online/opik_utils.py
CHANGED
|
@@ -1,77 +1,60 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
from loguru import logger
|
| 5 |
-
from opik.configurator.configure import OpikConfigurator
|
| 6 |
-
|
| 7 |
-
from second_brain_online.config import settings
|
| 8 |
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
else
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
def get_or_create_dataset(name: str, prompts: list[str]) -> opik.Dataset | None:
|
| 39 |
-
client = opik.Opik()
|
| 40 |
try:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
)
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
description="Dataset for evaluating the agentic app.",
|
| 63 |
-
items=dataset_items,
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
return dataset
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
def create_dataset(name: str, description: str, items: list[dict]) -> opik.Dataset:
|
| 70 |
-
client = opik.Opik()
|
| 71 |
-
|
| 72 |
-
dataset = client.get_or_create_dataset(name=name, description=description)
|
| 73 |
-
dataset.insert(items)
|
| 74 |
-
|
| 75 |
-
dataset = client.get_dataset(name=name)
|
| 76 |
-
|
| 77 |
-
return dataset
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Hugging Face Space app for Second Brain AI Assistant.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
Direct implementation for HF Space deployment.
|
| 6 |
+
"""
|
| 7 |
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
# Add the current directory and src directory to Python path
|
| 13 |
+
sys.path.append('.')
|
| 14 |
+
sys.path.append('src')
|
| 15 |
+
|
| 16 |
+
from second_brain_online.application.agents import get_agent
|
| 17 |
+
from second_brain_online.application.ui import CustomGradioUI
|
| 18 |
+
from second_brain_online import opik_utils
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
"""Main function for Hugging Face Space deployment."""
|
| 22 |
+
# Set default values for HF Spaces
|
| 23 |
+
retriever_config_path = os.getenv("RETRIEVER_CONFIG_PATH", "configs/compute_rag_vector_index_openai_contextual_simple.yaml")
|
| 24 |
+
|
| 25 |
+
print("π Starting Second Brain AI Assistant...")
|
| 26 |
+
print(f"π Using retriever config: {retriever_config_path}")
|
| 27 |
+
|
| 28 |
+
# Debug: Check environment variables
|
| 29 |
+
print("π Environment variables check:")
|
| 30 |
+
print(f" COMET_API_KEY: {'SET' if os.getenv('COMET_API_KEY') else 'NOT SET'}")
|
| 31 |
+
print(f" COMET_PROJECT: {os.getenv('COMET_PROJECT', 'NOT SET')}")
|
| 32 |
+
print(f" OPENAI_API_KEY: {'SET' if os.getenv('OPENAI_API_KEY') else 'NOT SET'}")
|
| 33 |
+
print(f" MONGODB_URI: {'SET' if os.getenv('MONGODB_URI') else 'NOT SET'}")
|
| 34 |
+
|
| 35 |
+
# Configure OPIK (optional - will use default project if COMET_PROJECT not set)
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
+
opik_utils.configure()
|
| 38 |
+
print("β
OPIK configured successfully")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"β οΈ OPIK configuration failed: {e}")
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
# Initialize agent
|
| 44 |
+
agent = get_agent(retriever_config_path=Path(retriever_config_path))
|
| 45 |
+
|
| 46 |
+
# Get the actual agent from the wrapper
|
| 47 |
+
actual_agent = agent._AgentWrapper__agent
|
| 48 |
+
|
| 49 |
+
# Launch custom UI
|
| 50 |
+
CustomGradioUI(actual_agent).launch(
|
| 51 |
+
server_name="0.0.0.0",
|
| 52 |
+
server_port=7860,
|
| 53 |
+
share=False
|
| 54 |
)
|
| 55 |
+
except Exception as e:
|
| 56 |
+
print(f"β Error starting the application: {e}")
|
| 57 |
+
raise
|
| 58 |
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|