fix(setup,chat): pass dummy api_key for local providers
litellm requires the api_key field even for local OpenAI-compatible servers (LM Studio, llama.cpp). Use "local" as a sentinel value for providers that don't require a real key. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -102,17 +102,17 @@ def _call_ai(cfg: PyraConfig, history: ConversationHistory) -> str:
|
|||||||
from pyra.vault.reader import get_key
|
from pyra.vault.reader import get_key
|
||||||
|
|
||||||
provider = get_provider(cfg.ai.provider_id)
|
provider = get_provider(cfg.ai.provider_id)
|
||||||
api_key = get_key(cfg.ai.provider_id) if provider.requires_key else None
|
# Local providers don't need a real key but litellm requires the field
|
||||||
|
api_key = get_key(cfg.ai.provider_id) if provider.requires_key else "local"
|
||||||
|
|
||||||
kwargs: dict = {
|
kwargs: dict = {
|
||||||
"model": f"{provider.litellm_prefix}{cfg.ai.model}",
|
"model": f"{provider.litellm_prefix}{cfg.ai.model}",
|
||||||
"messages": history.build_for_api(),
|
"messages": history.build_for_api(),
|
||||||
"stream": True,
|
"stream": True,
|
||||||
|
"api_key": api_key,
|
||||||
}
|
}
|
||||||
if cfg.ai.base_url:
|
if cfg.ai.base_url:
|
||||||
kwargs["api_base"] = cfg.ai.base_url
|
kwargs["api_base"] = cfg.ai.base_url
|
||||||
if api_key:
|
|
||||||
kwargs["api_key"] = api_key
|
|
||||||
|
|
||||||
litellm.suppress_debug_info = True
|
litellm.suppress_debug_info = True
|
||||||
stream = litellm.completion(**kwargs)
|
stream = litellm.completion(**kwargs)
|
||||||
|
|||||||
@@ -121,16 +121,16 @@ def _test_connection(provider: Provider, model: str) -> None:
|
|||||||
try:
|
try:
|
||||||
import litellm
|
import litellm
|
||||||
|
|
||||||
api_key = get_key(provider.id) if provider.requires_key else "no-key"
|
# Local providers don't need a real key but litellm still requires the field
|
||||||
|
api_key = get_key(provider.id) if provider.requires_key else "local"
|
||||||
kwargs: dict = {
|
kwargs: dict = {
|
||||||
"model": f"{provider.litellm_prefix}{model}",
|
"model": f"{provider.litellm_prefix}{model}",
|
||||||
"messages": [{"role": "user", "content": "Reply with exactly: OK"}],
|
"messages": [{"role": "user", "content": "Reply with exactly: OK"}],
|
||||||
"max_tokens": 10,
|
"max_tokens": 10,
|
||||||
|
"api_key": api_key,
|
||||||
}
|
}
|
||||||
if provider.base_url:
|
if provider.base_url:
|
||||||
kwargs["api_base"] = provider.base_url
|
kwargs["api_base"] = provider.base_url
|
||||||
if api_key and api_key != "no-key":
|
|
||||||
kwargs["api_key"] = api_key
|
|
||||||
|
|
||||||
litellm.completion(**kwargs)
|
litellm.completion(**kwargs)
|
||||||
console.print("[green]✓ Connection OK[/green]")
|
console.print("[green]✓ Connection OK[/green]")
|
||||||
|
|||||||
Reference in New Issue
Block a user