-
-
Notifications
You must be signed in to change notification settings - Fork 8
fix: resolve webpack runtime error in resolution search #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
30eab84
8621049
8f961c9
0e1f214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { getSelectedModel } from '@/lib/actions/users' | ||
| import { createOpenAI } from '@ai-sdk/openai' | ||
| import { createGoogleGenerativeAI } from '@ai-sdk/google' | ||
| import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock' | ||
| import { createXai } from '@ai-sdk/xai' | ||
|
|
||
| export async function getModel(requireVision: boolean = false) { | ||
| const selectedModel = await getSelectedModel(); | ||
|
|
||
| const xaiApiKey = process.env.XAI_API_KEY; | ||
| const gemini3ProApiKey = process.env.GEMINI_3_PRO_API_KEY; | ||
| const awsAccessKeyId = process.env.AWS_ACCESS_KEY_ID; | ||
| const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY; | ||
| const awsRegion = process.env.AWS_REGION; | ||
| const bedrockModelId = process.env.BEDROCK_MODEL_ID || 'anthropic.claude-3-5-sonnet-20241022-v2:0'; | ||
| const openaiApiKey = process.env.OPENAI_API_KEY; | ||
|
|
||
| if (selectedModel) { | ||
| switch (selectedModel) { | ||
| case 'Grok 4.2': | ||
| if (xaiApiKey) { | ||
| const xai = createXai({ | ||
| apiKey: xaiApiKey, | ||
| baseURL: 'https://api.x.ai/v1', | ||
| }); | ||
| try { | ||
| const modelId = requireVision ? 'grok-vision-beta' : 'grok-2-1212'; | ||
| return xai(modelId); | ||
| } catch (error) { | ||
| console.error('Selected model "Grok 4.2" is configured but failed to initialize.', error); | ||
| throw new Error('Failed to initialize selected model.'); | ||
| } | ||
| } else { | ||
| console.error('User selected "Grok 4.2" but XAI_API_KEY is not set.'); | ||
| throw new Error('Selected model is not configured.'); | ||
| } | ||
| case 'Gemini 3': | ||
| case 'Gemini 3.1 Pro': | ||
| if (gemini3ProApiKey) { | ||
| const google = createGoogleGenerativeAI({ | ||
| apiKey: gemini3ProApiKey, | ||
| }); | ||
| try { | ||
| return google('gemini-1.5-pro-latest'); | ||
| } catch (error) { | ||
| console.error('Selected model "Gemini 3.1 Pro" is configured but failed to initialize.', error); | ||
| throw new Error('Failed to initialize selected model.'); | ||
| } | ||
| } else { | ||
| console.error('User selected "Gemini 3.1 Pro" but GEMINI_3_PRO_API_KEY is not set.'); | ||
| throw new Error('Selected model is not configured.'); | ||
| } | ||
| case 'GPT-5.1': | ||
| if (openaiApiKey) { | ||
| const openai = createOpenAI({ | ||
| apiKey: openaiApiKey, | ||
| }); | ||
| return openai('gpt-4o'); | ||
| } else { | ||
| console.error('User selected "GPT-5.1" but OPENAI_API_KEY is not set.'); | ||
| throw new Error('Selected model is not configured.'); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Default behavior: Grok -> Gemini -> Bedrock -> OpenAI | ||
| if (xaiApiKey) { | ||
| const xai = createXai({ | ||
| apiKey: xaiApiKey, | ||
| baseURL: 'https://api.x.ai/v1', | ||
| }); | ||
| try { | ||
| const modelId = requireVision ? 'grok-vision-beta' : 'grok-latest'; | ||
| return xai(modelId); | ||
| } catch (error) { | ||
| console.warn('xAI API unavailable, falling back to next provider:'); | ||
| } | ||
| } | ||
|
|
||
| if (gemini3ProApiKey) { | ||
| const google = createGoogleGenerativeAI({ | ||
| apiKey: gemini3ProApiKey, | ||
| }); | ||
| try { | ||
| return google('gemini-1.5-pro-latest'); | ||
| } catch (error) { | ||
| console.warn('Gemini 3.1 Pro API unavailable, falling back to next provider:', error); | ||
| } | ||
| } | ||
|
|
||
| if (awsAccessKeyId && awsSecretAccessKey) { | ||
| const bedrock = createAmazonBedrock({ | ||
| bedrockOptions: { | ||
| region: awsRegion, | ||
| credentials: { | ||
| accessKeyId: awsAccessKeyId, | ||
| secretAccessKey: awsSecretAccessKey, | ||
| }, | ||
| }, | ||
| }); | ||
| const model = bedrock(bedrockModelId, { | ||
| additionalModelRequestFields: { top_k: 350 }, | ||
| }); | ||
| return model; | ||
| } | ||
|
|
||
| const openai = createOpenAI({ | ||
| apiKey: openaiApiKey, | ||
| }); | ||
| return openai('gpt-4o'); | ||
|
Comment on lines
+66
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== file list =="
git ls-files lib/utils/server.ts
echo
echo "== file size =="
wc -l lib/utils/server.ts
echo
echo "== outline =="
ast-grep outline lib/utils/server.ts --view expanded
echo
echo "== relevant lines =="
sed -n '1,220p' lib/utils/server.ts | cat -n
echo
echo "== search for consumers of the returned model =="
rg -n "create[A-Za-z]+\\(|generateText\\(|streamObject\\(|return .*openai\\(|return .*google\\(|return .*xai\\(" lib -g '!**/dist/**' -g '!**/build/**'Repository: QueueLab/QCX Length of output: 6969 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== getModel call sites =="
rg -n "\bgetModel\(" lib -g '!**/dist/**' -g '!**/build/**'
echo
echo "== AI SDK provider/generation docs lookup =="
python3 - <<'PY'
import urllib.request, urllib.parse, json, re
queries = [
"ai sdk provider factory returns model object generateText streamObject network request happens later",
"site:ai-sdk.dev createOpenAI model object generateText streamObject",
]
for q in queries:
print(f"\nQUERY: {q}")
PYRepository: QueueLab/QCX Length of output: 1264 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== ai-sdk dependencies =="
rg -n '"`@ai-sdk/`|ai"' package.json pnpm-lock.yaml package-lock.json yarn.lock -g '!**/node_modules/**'
echo
echo "== provider factories in repo =="
rg -n "create(OpenAI|GoogleGenerativeAI|AmazonBedrock|Xai)\(" lib package.json -g '!**/node_modules/**'Repository: QueueLab/QCX Length of output: 684 🌐 Web query:
💡 Result: When you use factory functions like createOpenAI, createGoogleGenerativeAI, or createXai in the Vercel AI SDK, they do not initiate any network requests at the time of creation [1][2]. These functions simply return a provider instance—a configuration object containing the settings (such as API keys, base URLs, and headers) and the logic required to instantiate specific language models later [1][3][2]. The network request only occurs later, when you actually use the returned language model object in a function such as generateText or streamText [4][5][6]. At that point, the SDK uses the configuration defined in your provider instance to construct and execute the API call to the respective AI service [1][3][7]. Citations:
Move fallback selection to the generation path. 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| 'use client'; | ||
|
|
||
| import { useState, useCallback, useRef, useEffect } from 'react'; | ||
| import { generateText } from 'ai'; | ||
| import { getModel } from '@/lib/utils'; | ||
| import { getModel } from '@/lib/utils/server'; | ||
|
Comment on lines
+1
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift Do not import the server model utility into a Client Component.
🤖 Prompt for AI Agents |
||
|
|
||
| // Define Tool type locally if needed | ||
| type Tool = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Honor the model selected by the user.
These branches silently substitute older models:
Grok 4.2returnsgrok-2-1212, both Gemini 3 choices return Gemini 1.5, andGPT-5.1returns GPT-4o. Align the persisted option names with the actual model IDs or reject unsupported selections instead of returning a different model.🤖 Prompt for AI Agents