openrag/src/utils/langflow_headers.py
Edwin Jose 0f2012bbb9 Update Langflow tweaks and add provider credentials to headers
Replaces all references to 'OpenSearchHybrid-Ve6bS' with 'OpenSearchVectorStoreComponentMultimodalMultiEmbedding-By9U4' in main.py, processors, and file service. Adds a utility for injecting provider credentials into Langflow request headers and integrates it into chat and file services for improved credential handling.
2025-11-25 22:50:38 -05:00

33 lines
1.4 KiB
Python

"""Utility functions for building Langflow request headers."""
from typing import Dict
from utils.container_utils import transform_localhost_url
def add_provider_credentials_to_headers(headers: Dict[str, str], config) -> None:
"""Add provider credentials to headers as Langflow global variables.
Args:
headers: Dictionary of headers to add credentials to
config: OpenRAGConfig object containing provider configurations
"""
# Add OpenAI credentials
if config.providers.openai.api_key:
headers["X-LANGFLOW-GLOBAL-VAR-OPENAI_API_KEY"] = str(config.providers.openai.api_key)
# Add Anthropic credentials
if config.providers.anthropic.api_key:
headers["X-LANGFLOW-GLOBAL-VAR-ANTHROPIC_API_KEY"] = str(config.providers.anthropic.api_key)
# Add WatsonX credentials
if config.providers.watsonx.api_key:
headers["X-LANGFLOW-GLOBAL-VAR-WATSONX_API_KEY"] = str(config.providers.watsonx.api_key)
if config.providers.watsonx.project_id:
headers["X-LANGFLOW-GLOBAL-VAR-WATSONX_PROJECT_ID"] = str(config.providers.watsonx.project_id)
# Add Ollama endpoint (with localhost transformation)
if config.providers.ollama.endpoint:
ollama_endpoint = transform_localhost_url(config.providers.ollama.endpoint)
headers["X-LANGFLOW-GLOBAL-VAR-OLLAMA_BASE_URL"] = str(ollama_endpoint)