config.py
2.53 KB
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Configuration management for OmniShopAgent
Loads environment variables and provides configuration objects
"""
import os
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""Application settings loaded from environment variables
All settings can be configured via .env file or environment variables.
"""
# OpenAI Configuration
openai_api_key: str
openai_model: str = "gpt-4o-mini"
openai_embedding_model: str = "text-embedding-3-small"
openai_temperature: float = 0.7
openai_max_tokens: int = 1000
# CLIP Server Configuration
clip_server_url: str = "grpc://localhost:51000"
# Milvus Configuration
milvus_uri: str = "http://localhost:19530"
milvus_host: str = "localhost"
milvus_port: int = 19530
text_collection_name: str = "text_embeddings"
image_collection_name: str = "image_embeddings"
text_dim: int = 1536
image_dim: int = 512
@property
def milvus_uri_absolute(self) -> str:
"""Get absolute path for Milvus URI
Returns:
- For http/https URIs: returns as-is (Milvus Standalone)
- For file paths starting with ./: converts to absolute path (Milvus Lite)
- For other paths: returns as-is
"""
import os
# If it's a network URI, return as-is (Milvus Standalone)
if self.milvus_uri.startswith(("http://", "https://")):
return self.milvus_uri
# If it's a relative path, convert to absolute (Milvus Lite)
if self.milvus_uri.startswith("./"):
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_dir, self.milvus_uri[2:])
# Otherwise return as-is
return self.milvus_uri
# Search Configuration
top_k_results: int = 10
similarity_threshold: float = 0.6
# Application Configuration
app_host: str = "0.0.0.0"
app_port: int = 8000
debug: bool = True
log_level: str = "INFO"
# Data Paths
raw_data_path: str = "./data/raw"
processed_data_path: str = "./data/processed"
image_data_path: str = "./data/images"
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = False
# Global settings instance
settings = Settings()
# Helper function to get absolute paths
def get_absolute_path(relative_path: str) -> str:
"""Convert relative path to absolute path"""
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_dir, relative_path)