diff --git a/agency/.env.template b/agency/.env.template index a551e1cc..02a9fbbd 100644 --- a/agency/.env.template +++ b/agency/.env.template @@ -21,28 +21,6 @@ # SEARCH__BASE_URL= # SEARCH__LOCALE= -# Brave Search API Configuration -# BRAVE__API_ROOT= -BRAVE__SUBSCRIPTION_KEY= -# BRAVE__RESULT_COUNT= -BRAVE__GOGGLES_ID= -# BRAVE__RESULT_FILTER= - -# LLM and TogetherAI API Configuration -# TOGETHER__API_ROOT= -TOGETHER__API_KEY= -# TOGETHER__MODEL= - -# BioLLM API Configuration -# BIOLLM__MODEL_NAME= -# BIOLLM__API_URL= -# BIOLLM__TEMPERATURE= -# BIOLLM__MAX_TOKENS= -# BIOLLM__PROMPT_TOKEN_LIMIT= - -# OpenAI API Configuration -OPENAI__API_KEY= - # Embedding Model Configuration # EMBEDDING__API_URL= EMBEDDING__API_KEY= @@ -53,29 +31,10 @@ EMBEDDING__API_KEY= SPLADEEMBEDDING__API_KEY= # EMBEDDING__BATCH_SIZE= -# Post Processing Settings -# POST_PROCESS__API= -# POST_PROCESS__MAX_TOKENS_PER_NODE= -# POST_PROCESS__COMPRESSED_TARGET_TOKENS= -# POST_PROCESS__TOP_N_SOURCES= - -# Nebula Graph Configuration -# NEBULA_GRAPH__HOST= -# NEBULA_GRAPH__PORT= -NEBULA_GRAPH__USER= -NEBULA_GRAPH__PASSWORD= -# NEBULA_GRAPH__SPACE= - # Redis Configuration REDIS__URL= # REDIS__DEFAULT_EXPIRY= -# WANDB Configuration -WANDB__API_KEY= -# WANDB__PROJECT= -# WANDB__ENTITY= -# WANDB__NOTE= - # Tracing Configuration TRACING__SENTRY_DSN= # TRACING__ENABLE_TRACING= @@ -85,9 +44,6 @@ TRACING__SENTRY_DSN= # TRACING__SERVICE_NAME= # TRACING__JAEGER_ENDPOINT= -# GROQ API Configuration -GROQ__API_KEY= - # Pubmed Parent Qdrant API Configuration # PUBMED_PARENT_QDRANT__API_PORT= # PUBMED_PARENT_QDRANT__API_URL= @@ -106,15 +62,6 @@ PUBMED_CLUSTER_QDRANT__API_KEY= # PUBMED_CLUSTER_QDRANT__SPARSE_TOP_K= # PUBMED_CLUSTER_QDRANT__METADATA_FIELD_NAME= -# Clinical Trial Qdrant API Configuration -# CLINICAL_TRIAL_QDRANT__API_PORT= -# CLINICAL_TRIAL_QDRANT__API_URL= -CLINICAL_TRIAL_QDRANT__API_KEY= -# CLINICAL_TRIAL_QDRANT__COLLECTION_NAME= -# CLINICAL_TRIAL_QDRANT__TOP_K= -# CLINICAL_TRIAL_QDRANT__SPARSE_TOP_K= -# CLINICAL_TRIAL_QDRANT__METADATA_FIELD_NAME= - # Pubmed Retrieval Configuration # PUBMED_RETRIEVAL__PARENT_RELEVANCE_CRITERIA= # PUBMED_RETRIEVAL__CLUSTER_RELEVANCE_CRITERIA= diff --git a/agency/README.md b/agency/README.md index abc5345f..96490687 100644 --- a/agency/README.md +++ b/agency/README.md @@ -56,6 +56,10 @@ Agency is a collection of multiple RAG modules. Every module is responsible for # configure the environment variables cp .env.template .env +# Copy the environment variables from the aws secret file +# https://eu-central-1.console.aws.amazon.com/secretsmanager/secret?name=search-agency-development-env®ion=eu-central-1 +# and turn on curieo vpn + # start the server poetry run app ``` diff --git a/agency/app/settings.py b/agency/app/settings.py index ceef454d..4697a4d5 100644 --- a/agency/app/settings.py +++ b/agency/app/settings.py @@ -24,49 +24,6 @@ class SearchSettings(BaseSettings): locale: str = "en-US" -class BraveSettings(BaseSettings): - api_root: str = "https://api.search.brave.com/res/v1/web/search" - subscription_key: SecretStr - result_count: int = 10 - goggles_id: SecretStr - result_filter: list[str] = [ - "discussions", - "faq", - "summarizer", - "infobox", - "news", - "query", - "web", - ] - - -class TogetherPromptConfig(BaseSettings): - max_tokens: int = 1024 - temperature: float = 0.7 - top_p: float = 0.7 - prompt_token_limit: int = 4096 - stream: bool = True - - -class TogetherSettings(BaseSettings): - api_root: str = "https://api.together.xyz/v1/completions" - api_key: SecretStr - model: str = "mistralai/Mistral-7B-Instruct-v0.1" - prompt_config: TogetherPromptConfig = TogetherPromptConfig() - - -class BioLLMSettings(BaseSettings): - model_name: str = "ivarflakstad/Llama3-OpenBioLLM-8B" - api_url: str = "http://localhost:8085" - temperature: float = 0.1 - max_tokens: int = 1000 - prompt_token_limit: int = 3000 - - -class OpenAISettings(BaseSettings): - api_key: SecretStr - - class EmbeddingSettings(BaseSettings): api_url: str = "http://localhost:8080" api_key: SecretStr @@ -79,40 +36,11 @@ class SpladeEmbeddingSettings(BaseSettings): batch_size: int = 4 -class PostProcessingSettings(BaseSettings): - api: str = "http://localhost:8000/compress" - max_tokens_per_node: int = 512 - compressed_target_token: int = 300 - top_n_sources: int = 10 - - -class TableInfoDirSettings(BaseSettings): - clinical_trials: str = ( - "app/rag/retrieval/clinical_trials/AACTTableQuestions_TableInfo" - ) - drug_chembl: str = "app/rag/retrieval/drug_chembl/ChEMBLTableQuestions_TableInfo" - - -class NebulaGraphSettings(BaseSettings): - host: str = "http://127.0.0.1" - port: int = 9669 - user: SecretStr - password: SecretStr - space: str = "chembl" - - class RedisSettings(BaseSettings): url: SecretStr default_expiry: int = 86400 -class WandbSettings(BaseSettings): - api_key: SecretStr - project: str = "pe_router" - entity: str = "curieo" - note: str = "Curieo Search" - - class TracingSettings(BaseSettings): sentry_dsn: SecretStr jaeger_endpoint: str = "http://127.0.0.1:4317" @@ -123,10 +51,6 @@ class TracingSettings(BaseSettings): service_name: str = "agency-service" -class GroqSettings(BaseSettings): - api_key: SecretStr - - class QdrantSettings(BaseSettings): api_port: int = 6333 api_url: str = "localhost" @@ -143,27 +67,6 @@ class PubmedRetrievalSettings(BaseSettings): url_prefix: str = "https://pubmed.ncbi.nlm.nih.gov" -class DspySettings(BaseSettings): - clinical_trial_sql_program: str = ( - "app/dspy_integration/dspy_programs/clinical_trials_sql_generation.json" - ) - clinical_trials_response_refinement_program: str = ( - "app/dspy_integration/dspy_programs/clinical_trials_response_refinement.json" - ) - orchestrator_router_prompt_program: str = ( - "app/dspy_integration/dspy_programs/orchestrator_router_prompt.json" - ) - - -class AIModelsSettings(BaseSettings): - router: str = "gpt-3.5-turbo" - sql_generation: str = "codellama/CodeLlama-13b-Instruct-hf" - clinical_trail_response_synthesizer_model: str = ( - "NousResearch/Nous-Hermes-llama-2-7b" - ) - pubmed_response_synthesizer_model: str = "mistralai/Mixtral-8x7B-Instruct-v0.1" - - class PubmedDatabaseSettings(BaseSettings): connection: SecretStr children_text_table_name: str = "pubmed_text_details" @@ -181,25 +84,13 @@ class Settings(BaseSettings): pubmed_database: PubmedDatabaseSettings project: ProjectSettings = ProjectSettings() search: SearchSettings = SearchSettings() - brave: BraveSettings - together: TogetherSettings - openai: OpenAISettings - nebula_graph: NebulaGraphSettings redis: RedisSettings - wandb: WandbSettings | None = None tracing: TracingSettings - groq: GroqSettings - dspy: DspySettings = DspySettings() embedding: EmbeddingSettings spladeembedding: SpladeEmbeddingSettings - post_process: PostProcessingSettings = PostProcessingSettings() - biollm: BioLLMSettings = BioLLMSettings() pubmed_parent_qdrant: QdrantSettings pubmed_cluster_qdrant: QdrantSettings - clinical_trial_qdrant: QdrantSettings pubmed_retrieval: PubmedRetrievalSettings = PubmedRetrievalSettings() - table_info_dir: TableInfoDirSettings = TableInfoDirSettings() - ai_models: AIModelsSettings = AIModelsSettings() app_settings = Settings() diff --git a/agency/app/database/nebula_graph.py b/agency/develop/database/nebula_graph.py similarity index 100% rename from agency/app/database/nebula_graph.py rename to agency/develop/database/nebula_graph.py diff --git a/agency/develop/settings.py b/agency/develop/settings.py new file mode 100644 index 00000000..ceef454d --- /dev/null +++ b/agency/develop/settings.py @@ -0,0 +1,205 @@ +# Load environment variables from .env file +from pydantic import SecretStr +from pydantic_settings import BaseSettings, SettingsConfigDict + + +class ProjectSettings(BaseSettings): + name: str = "Curieo Search" + environment: str = "production" + version: str = "0.0.1" + default_base_url: str = "http://127.0.0.1" + port: int = 50051 + graceful_shutdown_period: int = 5 + max_grpc_workers: int = 10 + debug: bool = True + testing: bool = True + show_request_process_time_header: bool = True + prompt_language: str = "en-US" + + +class SearchSettings(BaseSettings): + api_root: str = "http://127.0.0.1" + api_public_url: str = "http://127.0.0.1" + api_base_url: str = "http://127.0.0.1" + locale: str = "en-US" + + +class BraveSettings(BaseSettings): + api_root: str = "https://api.search.brave.com/res/v1/web/search" + subscription_key: SecretStr + result_count: int = 10 + goggles_id: SecretStr + result_filter: list[str] = [ + "discussions", + "faq", + "summarizer", + "infobox", + "news", + "query", + "web", + ] + + +class TogetherPromptConfig(BaseSettings): + max_tokens: int = 1024 + temperature: float = 0.7 + top_p: float = 0.7 + prompt_token_limit: int = 4096 + stream: bool = True + + +class TogetherSettings(BaseSettings): + api_root: str = "https://api.together.xyz/v1/completions" + api_key: SecretStr + model: str = "mistralai/Mistral-7B-Instruct-v0.1" + prompt_config: TogetherPromptConfig = TogetherPromptConfig() + + +class BioLLMSettings(BaseSettings): + model_name: str = "ivarflakstad/Llama3-OpenBioLLM-8B" + api_url: str = "http://localhost:8085" + temperature: float = 0.1 + max_tokens: int = 1000 + prompt_token_limit: int = 3000 + + +class OpenAISettings(BaseSettings): + api_key: SecretStr + + +class EmbeddingSettings(BaseSettings): + api_url: str = "http://localhost:8080" + api_key: SecretStr + batch_size: int = 4 + + +class SpladeEmbeddingSettings(BaseSettings): + api: str = "http://localhost:8081" + api_key: SecretStr + batch_size: int = 4 + + +class PostProcessingSettings(BaseSettings): + api: str = "http://localhost:8000/compress" + max_tokens_per_node: int = 512 + compressed_target_token: int = 300 + top_n_sources: int = 10 + + +class TableInfoDirSettings(BaseSettings): + clinical_trials: str = ( + "app/rag/retrieval/clinical_trials/AACTTableQuestions_TableInfo" + ) + drug_chembl: str = "app/rag/retrieval/drug_chembl/ChEMBLTableQuestions_TableInfo" + + +class NebulaGraphSettings(BaseSettings): + host: str = "http://127.0.0.1" + port: int = 9669 + user: SecretStr + password: SecretStr + space: str = "chembl" + + +class RedisSettings(BaseSettings): + url: SecretStr + default_expiry: int = 86400 + + +class WandbSettings(BaseSettings): + api_key: SecretStr + project: str = "pe_router" + entity: str = "curieo" + note: str = "Curieo Search" + + +class TracingSettings(BaseSettings): + sentry_dsn: SecretStr + jaeger_endpoint: str = "http://127.0.0.1:4317" + enable_tracing: bool = False + environment: str = "development" + phoenix_api: str = "http://127.0.0.1:4317" + project_name: str = "Curieo Search" + service_name: str = "agency-service" + + +class GroqSettings(BaseSettings): + api_key: SecretStr + + +class QdrantSettings(BaseSettings): + api_port: int = 6333 + api_url: str = "localhost" + api_key: SecretStr + collection_name: str = "pubmed_hybrid" + top_k: int = 10 + sparse_top_k: int = 5 + metadata_field_name: str = "title" + + +class PubmedRetrievalSettings(BaseSettings): + parent_relevance_criteria: float = 0.1 + cluster_relevance_criteria: float = 0.1 + url_prefix: str = "https://pubmed.ncbi.nlm.nih.gov" + + +class DspySettings(BaseSettings): + clinical_trial_sql_program: str = ( + "app/dspy_integration/dspy_programs/clinical_trials_sql_generation.json" + ) + clinical_trials_response_refinement_program: str = ( + "app/dspy_integration/dspy_programs/clinical_trials_response_refinement.json" + ) + orchestrator_router_prompt_program: str = ( + "app/dspy_integration/dspy_programs/orchestrator_router_prompt.json" + ) + + +class AIModelsSettings(BaseSettings): + router: str = "gpt-3.5-turbo" + sql_generation: str = "codellama/CodeLlama-13b-Instruct-hf" + clinical_trail_response_synthesizer_model: str = ( + "NousResearch/Nous-Hermes-llama-2-7b" + ) + pubmed_response_synthesizer_model: str = "mistralai/Mixtral-8x7B-Instruct-v0.1" + + +class PubmedDatabaseSettings(BaseSettings): + connection: SecretStr + children_text_table_name: str = "pubmed_text_details" + record_title_table_name: str = "pubmed_titles" + + +class Settings(BaseSettings): + model_config = SettingsConfigDict( + extra="allow", + env_file=".env", + env_file_encoding="utf-8", + env_nested_delimiter="__", + ) + + pubmed_database: PubmedDatabaseSettings + project: ProjectSettings = ProjectSettings() + search: SearchSettings = SearchSettings() + brave: BraveSettings + together: TogetherSettings + openai: OpenAISettings + nebula_graph: NebulaGraphSettings + redis: RedisSettings + wandb: WandbSettings | None = None + tracing: TracingSettings + groq: GroqSettings + dspy: DspySettings = DspySettings() + embedding: EmbeddingSettings + spladeembedding: SpladeEmbeddingSettings + post_process: PostProcessingSettings = PostProcessingSettings() + biollm: BioLLMSettings = BioLLMSettings() + pubmed_parent_qdrant: QdrantSettings + pubmed_cluster_qdrant: QdrantSettings + clinical_trial_qdrant: QdrantSettings + pubmed_retrieval: PubmedRetrievalSettings = PubmedRetrievalSettings() + table_info_dir: TableInfoDirSettings = TableInfoDirSettings() + ai_models: AIModelsSettings = AIModelsSettings() + + +app_settings = Settings() diff --git a/server/README.md b/server/README.md index fc582e8e..2e0e3aed 100644 --- a/server/README.md +++ b/server/README.md @@ -8,6 +8,7 @@ - [API Documentation](#api-documentation) - [Prerequisites](#prerequisites) - [Usage](#usage) + - [Contribution](#contribution) - [Deployment](#deployment) ## Introduction @@ -47,6 +48,9 @@ Additionally, in the `.env` file, some services get additional configuration. # setup the environment and configure cp .env.template .env +# Copy the environment variables from the aws secret file +# https://eu-central-1.console.aws.amazon.com/secretsmanager/secret?name=search-server-development-env®ion=eu-central-1 +# and turn on curieo vpn ``` - database (see below) @@ -65,7 +69,7 @@ To locally compile and run, optionally, you need to create new tables or schemas Maintain current ordering in the `migrations` directory; making sure that the order of schema creation is not create error in the database. -``` +```bash sqlx migrate add schema_name # configure the database