Skip to content

An AI-powered search engine with a generative UI

fix: model selection to use cloud.json configuration properly

Yoshiki Miura1c69ee5271fe
diff --git a/lib/streaming/create-chat-stream-response.ts b/lib/streaming/create-chat-stream-response.ts
index a32fac41..3463a797 100644
--- a/lib/streaming/create-chat-stream-response.ts
+++ b/lib/streaming/create-chat-stream-response.ts
@@ -164,18 +164,20 @@ export async function createChatStreamResponse(
const result = researchAgent.stream({ messages: modelMessages })
result.consumeStream()
// Stream with the research agent, including metadata
- writer.merge(result.toUIMessageStream({
- messageMetadata: ({ part }) => {
- // Send metadata when streaming starts
- if (part.type === 'start') {
- return {
- traceId: parentTraceId,
- searchMode,
- modelId: context.modelId
+ writer.merge(
+ result.toUIMessageStream({
+ messageMetadata: ({ part }) => {
+ // Send metadata when streaming starts
+ if (part.type === 'start') {
+ return {
+ traceId: parentTraceId,
+ searchMode,
+ modelId: context.modelId
+ }
}
}
- }
- }))
+ })
+ )
const responseMessages = (await result.response).messages
// Generate related questions
diff --git a/lib/utils/model-selection.ts b/lib/utils/model-selection.ts
index 4b4cada7..f0c8ddc7 100644
--- a/lib/utils/model-selection.ts
+++ b/lib/utils/model-selection.ts
@@ -5,10 +5,16 @@ import { ModelType } from '@/lib/types/model-type'
import { Model } from '@/lib/types/models'
const DEFAULT_MODEL: Model = {
- id: 'gpt-4o-mini',
- name: 'GPT-4o mini',
+ id: 'gpt-5-mini',
+ name: 'GPT-5 mini',
provider: 'OpenAI',
- providerId: 'openai'
+ providerId: 'openai',
+ providerOptions: {
+ openai: {
+ reasoningEffort: 'low',
+ reasoningSummary: 'auto'
+ }
+ }
}
interface ModelSelectionParams {
@@ -19,20 +25,30 @@ interface ModelSelectionParams {
* Determines which model to use based on the model type preference
*
* Priority order:
- * 1. If model type is in cookie -> use corresponding model
- * 2. Otherwise -> use DEFAULT_MODEL
+ * 1. If model type is in cookie -> use corresponding model from config
+ * 2. Otherwise -> use default 'speed' model from config
+ * 3. If config loading fails -> use DEFAULT_MODEL as fallback
*/
export function selectModel({ cookieStore }: ModelSelectionParams): Model {
const modelTypeCookie = cookieStore.get('modelType')?.value as
| ModelType
| undefined
- // If model type is set, use the corresponding model
- if (modelTypeCookie && ['speed', 'quality'].includes(modelTypeCookie)) {
- return getModelForType(modelTypeCookie)
+ try {
+ // If model type is set in cookie, use it
+ if (modelTypeCookie && ['speed', 'quality'].includes(modelTypeCookie)) {
+ const model = getModelForType(modelTypeCookie)
+ if (model) return model
+ }
+
+ // Default to 'speed' model from config when no cookie is set
+ const defaultModel = getModelForType('speed')
+ if (defaultModel) return defaultModel
+ } catch (error) {
+ console.error('Error loading model from config:', error)
}
- // Default model
+ // Fallback to hardcoded DEFAULT_MODEL if config loading fails
return DEFAULT_MODEL
}