mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 15:48:29 +00:00
Address GitHub review: remove URL construction helper and use provided URLs as-is
- Remove _construct_embeddings_url() method as requested by lucasgomide - Use URLs exactly as provided by config or environment variable - Add comprehensive documentation about API_BASE environment variable support - Maintain URL validation for security - Simplify implementation to avoid assumptions about URL formats across providers Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -108,17 +108,19 @@ class EmbeddingConfigurator:
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _construct_embeddings_url(base_url):
|
||||
"""Construct the full embeddings URL from a base URL."""
|
||||
if not base_url:
|
||||
return "http://localhost:11434/api/embeddings"
|
||||
|
||||
base_url = base_url.rstrip('/')
|
||||
return f"{base_url}/api/embeddings" if not base_url.endswith('/api/embeddings') else base_url
|
||||
|
||||
@staticmethod
|
||||
def _configure_ollama(config, model_name):
|
||||
"""Configure Ollama embedding function.
|
||||
|
||||
Supports configuration via:
|
||||
1. config.url - Direct URL to Ollama embeddings endpoint
|
||||
2. config.api_base - Base URL for Ollama API
|
||||
3. API_BASE environment variable - Base URL from environment
|
||||
4. Default: http://localhost:11434/api/embeddings
|
||||
|
||||
Note: When using api_base or API_BASE, ensure the URL includes the full
|
||||
embeddings endpoint path (e.g., http://localhost:11434/api/embeddings)
|
||||
"""
|
||||
from chromadb.utils.embedding_functions.ollama_embedding_function import (
|
||||
OllamaEmbeddingFunction,
|
||||
)
|
||||
@@ -127,12 +129,11 @@ class EmbeddingConfigurator:
|
||||
config.get("url")
|
||||
or config.get("api_base")
|
||||
or os.getenv("API_BASE")
|
||||
or "http://localhost:11434/api/embeddings"
|
||||
)
|
||||
|
||||
if url and not EmbeddingConfigurator._validate_url(url):
|
||||
if not EmbeddingConfigurator._validate_url(url):
|
||||
raise ValueError(f"Invalid Ollama API URL: {url}")
|
||||
|
||||
url = EmbeddingConfigurator._construct_embeddings_url(url)
|
||||
|
||||
return OllamaEmbeddingFunction(
|
||||
url=url,
|
||||
|
||||
Reference in New Issue
Block a user