-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathllm_options.py
More file actions
39 lines (32 loc) · 1.42 KB
/
Copy pathllm_options.py
File metadata and controls
39 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import Optional
from .types import LLMProvider
def build_llm_payload(
llm_provider: Optional[LLMProvider] = None,
llm_model: Optional[str] = None,
llm_api_key: Optional[str] = None,
llm_base_url: Optional[str] = None,
) -> dict:
"""Returns only the LLM options that were explicitly supplied.
All-or-nothing: omit every option to use the platform's own models (the only
thing Maxun Cloud accepts), or supply a complete configuration for a
self-hosted instance. A partial configuration raises here rather than at the
server, so the error names the missing field immediately.
``llm_model`` is optional: self-hosted Maxun applies that provider's default
when it is omitted, so robots created before model selection existed keep
working without a migration.
"""
provider = (llm_provider or "").strip()
model = (llm_model or "").strip()
api_key = (llm_api_key or "").strip()
base_url = (llm_base_url or "").strip()
if model and not provider:
raise ValueError("llm_provider is required when llm_model is set.")
if provider and provider != "ollama" and not api_key:
raise ValueError(f'llm_api_key is required for provider "{provider}".')
payload = {
"llmProvider": provider,
"llmModel": model,
"llmApiKey": api_key,
"llmBaseUrl": base_url,
}
return {key: value for key, value in payload.items() if value}