fix: use provider_type for model prefix and base_url for Ollama Cloud
- _get_llm_api_key now returns provider_type - Model string built with provider_type prefix (openai/deepseek-v4 instead of ollama/deepseek-v4) - api_base set from provider.base_url (https://ollama.com/v1) - Fixes: litellm tried localhost:11434 instead of Ollama Cloud
This commit is contained in:
@@ -190,10 +190,16 @@ async def deep_analysis(
|
|||||||
|
|
||||||
# Get API key from DB (like ai_assistant does) or fall back to env
|
# Get API key from DB (like ai_assistant does) or fall back to env
|
||||||
from app.plugins.builtins.ai_proactive.services import _get_llm_api_key
|
from app.plugins.builtins.ai_proactive.services import _get_llm_api_key
|
||||||
api_key, api_base = await _get_llm_api_key(db, tid)
|
api_key, api_base, provider_type = await _get_llm_api_key(db, tid)
|
||||||
if not api_key:
|
if not api_key:
|
||||||
api_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '') or None
|
api_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '') or None
|
||||||
|
|
||||||
|
# Build model string with provider prefix
|
||||||
|
model = settings.model or "ollama/deepseek-v4"
|
||||||
|
if provider_type:
|
||||||
|
model_parts = model.split("/", 1)
|
||||||
|
model = f"{provider_type}/{model_parts[-1]}"
|
||||||
|
|
||||||
litellm_kwargs: dict[str, Any] = dict(
|
litellm_kwargs: dict[str, Any] = dict(
|
||||||
model=model,
|
model=model,
|
||||||
messages=[
|
messages=[
|
||||||
|
|||||||
@@ -33,22 +33,22 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
litellm.suppress_debug_info = True
|
litellm.suppress_debug_info = True
|
||||||
|
|
||||||
async def _get_llm_api_key(db: AsyncSession, tenant_id: uuid.UUID) -> tuple[str | None, str | None]:
|
async def _get_llm_api_key(db: AsyncSession, tenant_id: uuid.UUID) -> tuple[str | None, str | None, str | None]:
|
||||||
"""Get API key and base_url from the default AI provider in the DB.
|
"""Get API key, base_url and provider_type from the default AI provider in the DB.
|
||||||
|
|
||||||
Falls back to API_KEY_OLLAMA_CLOUD env var if no provider found.
|
Falls back to API_KEY_OLLAMA_CLOUD env var if no provider found.
|
||||||
Returns (api_key, base_url).
|
Returns (api_key, base_url, provider_type).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from app.plugins.builtins.ai_assistant.services import get_default_provider
|
from app.plugins.builtins.ai_assistant.services import get_default_provider
|
||||||
provider = await get_default_provider(db, tenant_id)
|
provider = await get_default_provider(db, tenant_id)
|
||||||
if provider and provider.api_key:
|
if provider and provider.api_key:
|
||||||
return provider.api_key, provider.base_url
|
return provider.api_key, provider.base_url, provider.provider_type
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug("Failed to get provider from DB, falling back to env")
|
logger.debug("Failed to get provider from DB, falling back to env")
|
||||||
# Fallback to env var
|
# Fallback to env var
|
||||||
env_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '')
|
env_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '')
|
||||||
return (env_key if env_key else None), None
|
return (env_key if env_key else None), None, None
|
||||||
|
|
||||||
# ─── SSE Push Infrastructure ───
|
# ─── SSE Push Infrastructure ───
|
||||||
|
|
||||||
@@ -400,11 +400,18 @@ async def generate_suggestion(
|
|||||||
# Get API key from DB (like ai_assistant does) or fall back to env
|
# Get API key from DB (like ai_assistant does) or fall back to env
|
||||||
api_key = None
|
api_key = None
|
||||||
api_base = None
|
api_base = None
|
||||||
|
provider_type = None
|
||||||
if db and tenant_id:
|
if db and tenant_id:
|
||||||
api_key, api_base = await _get_llm_api_key(db, tenant_id)
|
api_key, api_base, provider_type = await _get_llm_api_key(db, tenant_id)
|
||||||
if not api_key:
|
if not api_key:
|
||||||
api_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '') or None
|
api_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '') or None
|
||||||
|
|
||||||
|
# Build model string with provider prefix (like ai_assistant build_litellm_params)
|
||||||
|
model = settings.model or "ollama/deepseek-v4"
|
||||||
|
if provider_type:
|
||||||
|
model_parts = model.split("/", 1)
|
||||||
|
model = f"{provider_type}/{model_parts[-1]}"
|
||||||
|
|
||||||
litellm_kwargs: dict[str, Any] = dict(
|
litellm_kwargs: dict[str, Any] = dict(
|
||||||
model=model,
|
model=model,
|
||||||
messages=[
|
messages=[
|
||||||
|
|||||||
Reference in New Issue
Block a user