fix: get LLM API key from DB instead of env var
- ai_proactive now reads API key from ai_providers table (like ai_assistant) - Falls back to API_KEY_OLLAMA_CLOUD env var if no provider found - Fixes: proactive engine could not generate suggestions because API key was empty
This commit is contained in:
@@ -187,23 +187,35 @@ async def deep_analysis(
|
||||
|
||||
# Generate extended suggestion with deep analysis prompt
|
||||
model = settings.model or "ollama/deepseek-v4"
|
||||
|
||||
# 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
|
||||
api_key, api_base = await _get_llm_api_key(db, tid)
|
||||
if not api_key:
|
||||
api_key = os.environ.get('API_KEY_OLLAMA_CLOUD', '') or None
|
||||
|
||||
litellm_kwargs: dict[str, Any] = dict(
|
||||
model=model,
|
||||
messages=[
|
||||
{"role": "system", "content": DEEP_SYSTEM_PROMPT},
|
||||
{
|
||||
"role": "user",
|
||||
"content": json.dumps(
|
||||
extended_context, default=str, ensure_ascii=False
|
||||
),
|
||||
},
|
||||
],
|
||||
temperature=0.3,
|
||||
max_tokens=800,
|
||||
response_format={"type": "json_object"},
|
||||
)
|
||||
if api_key:
|
||||
litellm_kwargs["api_key"] = api_key
|
||||
if api_base:
|
||||
litellm_kwargs["api_base"] = api_base
|
||||
|
||||
try:
|
||||
response = await litellm.acompletion(
|
||||
model=model,
|
||||
messages=[
|
||||
{"role": "system", "content": DEEP_SYSTEM_PROMPT},
|
||||
{
|
||||
"role": "user",
|
||||
"content": json.dumps(
|
||||
extended_context, default=str, ensure_ascii=False
|
||||
),
|
||||
},
|
||||
],
|
||||
temperature=0.3,
|
||||
max_tokens=800,
|
||||
response_format={"type": "json_object"},
|
||||
api_key=OLLAMA_API_KEY,
|
||||
)
|
||||
response = await litellm.acompletion(**litellm_kwargs)
|
||||
content = response.choices[0].message.content
|
||||
if not content:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user