fix(llm): Pass API key and base URL to memory compressor litellm calls
The memory compressor was calling litellm.completion() without passing the api_key and api_base parameters, causing authentication errors when LLM_API_KEY is set but provider-specific env vars (OPENAI_API_KEY, etc.) are not. This matches the pattern used in dedupe.py.
This commit is contained in:
@@ -104,12 +104,24 @@ def _summarize_messages(
|
|||||||
conversation = "\n".join(formatted)
|
conversation = "\n".join(formatted)
|
||||||
prompt = SUMMARY_PROMPT_TEMPLATE.format(conversation=conversation)
|
prompt = SUMMARY_PROMPT_TEMPLATE.format(conversation=conversation)
|
||||||
|
|
||||||
|
api_key = Config.get("llm_api_key")
|
||||||
|
api_base = (
|
||||||
|
Config.get("llm_api_base")
|
||||||
|
or Config.get("openai_api_base")
|
||||||
|
or Config.get("litellm_base_url")
|
||||||
|
or Config.get("ollama_api_base")
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
completion_args = {
|
completion_args: dict[str, Any] = {
|
||||||
"model": model,
|
"model": model,
|
||||||
"messages": [{"role": "user", "content": prompt}],
|
"messages": [{"role": "user", "content": prompt}],
|
||||||
"timeout": timeout,
|
"timeout": timeout,
|
||||||
}
|
}
|
||||||
|
if api_key:
|
||||||
|
completion_args["api_key"] = api_key
|
||||||
|
if api_base:
|
||||||
|
completion_args["api_base"] = api_base
|
||||||
|
|
||||||
response = litellm.completion(**completion_args)
|
response = litellm.completion(**completion_args)
|
||||||
summary = response.choices[0].message.content or ""
|
summary = response.choices[0].message.content or ""
|
||||||
|
|||||||
Reference in New Issue
Block a user