MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / buildPiModel

Function buildPiModel

packages/node-runtime/src/ai/llm-builder.ts:112–175  ·  view source on GitHub ↗
(config: PiModelConfig, options?: BuildPiModelOptions)

Source from the content-addressed store, hash-verified

110}
111
112export function buildPiModel(config: PiModelConfig, options?: BuildPiModelOptions): PiModel<PiApi> {
113 const providerDef = BUILTIN_PROVIDERS.find((p) => p.id === config.provider)
114 const baseUrl = config.baseUrl || providerDef?.defaultBaseUrl || ''
115 const modelId = config.model || ''
116
117 const findModel = options?.findModelFn ?? defaultFindModel
118 const modelDef = findModel(config.provider, modelId)
119 const contextWindow = modelDef?.contextWindow ?? DEFAULT_CONTEXT_WINDOW
120
121 const apiFormat: PiApi = (config.apiFormat as PiApi) || BUILTIN_PROVIDER_API[config.provider] || 'openai-completions'
122
123 if (apiFormat === 'google-generative-ai') {
124 return {
125 id: modelId,
126 name: modelId,
127 api: 'google-generative-ai',
128 provider: 'google',
129 baseUrl,
130 reasoning: isReasoningModel(config.provider, modelId),
131 input: ['text'],
132 cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
133 contextWindow,
134 maxTokens: config.maxTokens ?? 8192,
135 }
136 }
137
138 if (apiFormat === 'anthropic-messages') {
139 return {
140 id: modelId,
141 name: modelId,
142 api: 'anthropic-messages',
143 provider: 'anthropic',
144 baseUrl: normalizeAnthropicBaseUrl(baseUrl),
145 reasoning: false,
146 input: ['text'],
147 cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
148 contextWindow,
149 maxTokens: config.maxTokens ?? 8192,
150 }
151 }
152
153 const resolvedBaseUrl =
154 config.provider === 'openai-compatible' && (apiFormat === 'openai-completions' || apiFormat === 'openai-responses')
155 ? normalizeOpenAICompatibleBaseUrl(baseUrl)
156 : baseUrl
157
158 const { reasoning, compat, thinkingLevelMap } = inferReasoning(config.provider, modelId, modelDef)
159
160 return {
161 id: modelId,
162 name: modelId,
163 api: apiFormat,
164 provider: config.provider,
165 baseUrl: resolvedBaseUrl,
166 headers: options?.headers,
167 reasoning,
168 thinkingLevelMap,
169 input: ['text'],

Callers 5

buildPiModelFunction · 0.90
validateApiKeyFunction · 0.90

Calls 4

isReasoningModelFunction · 0.90
inferReasoningFunction · 0.85

Tested by

no test coverage detected