MCPcopy Create free account
hub / github.com/CopilotKit/OpenGenerativeUI / build_model

Function build_model

apps/agent/src/model.py:17–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15# langchain-anthropic defaults max_tokens to 4096, which truncates
16# generateSandboxedUi tool args mid-stream (jsFunctions/jsExpressions never
17# arrive and the widget is stuck in its preview sandbox). Widget generation
18# routinely needs tens of thousands of output tokens.
19MAX_TOKENS = 64000
20
21
22def build_model(*, allow_unconfigured: bool = False) -> BaseChatModel:
23 model_name = os.environ.get("LLM_MODEL", DEFAULT_MODEL).strip()
24 is_openai = model_name == "chat-latest" or model_name.startswith("gpt-")
25 if not is_openai and not model_name.startswith("claude-"):
26 raise ValueError(
27 "LLM_MODEL must name a supported provider: claude-* (Anthropic) "
28 "or gpt-*/chat-latest (OpenAI). Unset LLM_MODEL to use the default."
29 )
30 key_name = "OPENAI_API_KEY" if is_openai else "ANTHROPIC_API_KEY"
31 if not os.environ.get(key_name, "").strip():
32 if allow_unconfigured:

Calls

no outgoing calls