MCPcopy
hub / github.com/jina-ai/node-DeepResearch / getModel

Function getModel

src/config.ts:91–128  ·  view source on GitHub ↗
(toolName: ToolName)

Source from the content-addressed store, hash-verified

89
90// Get model instance
91export function getModel(toolName: ToolName) {
92 const config = getToolConfig(toolName);
93 const providerConfig = (configJson.providers as Record<string, ProviderConfig | undefined>)[LLM_PROVIDER];
94
95 if (LLM_PROVIDER === 'openai') {
96 if (!OPENAI_API_KEY) {
97 throw new Error('OPENAI_API_KEY not found');
98 }
99
100 const opt: OpenAIProviderSettings = {
101 apiKey: OPENAI_API_KEY,
102 compatibility: providerConfig?.clientConfig?.compatibility
103 };
104
105 if (OPENAI_BASE_URL) {
106 opt.baseURL = OPENAI_BASE_URL;
107 }
108
109 return createOpenAI(opt)(config.model);
110 }
111
112 if (LLM_PROVIDER === 'vertex') {
113 const createVertex = require('@ai-sdk/google-vertex').createVertex;
114 if (toolName === 'searchGrounding') {
115 return createVertex({ project: process.env.GCLOUD_PROJECT, ...providerConfig?.clientConfig })(config.model, { useSearchGrounding: true });
116 }
117 return createVertex({ project: process.env.GCLOUD_PROJECT, ...providerConfig?.clientConfig })(config.model);
118 }
119
120 if (!GEMINI_API_KEY) {
121 throw new Error('GEMINI_API_KEY not found');
122 }
123
124 if (toolName === 'searchGrounding') {
125 return createGoogleGenerativeAI({ apiKey: GEMINI_API_KEY })(config.model, { useSearchGrounding: true });
126 }
127 return createGoogleGenerativeAI({ apiKey: GEMINI_API_KEY })(config.model);
128}
129
130// Validate required environment variables
131if (LLM_PROVIDER === 'gemini' && !GEMINI_API_KEY) throw new Error("GEMINI_API_KEY not found");

Callers 2

grounding.tsFile · 0.90
generateObjectMethod · 0.90

Calls 1

getToolConfigFunction · 0.85

Tested by

no test coverage detected