Skip to content

Conversation

@hllshiro
Copy link
Collaborator

@hllshiro hllshiro commented Jun 17, 2025

Pull Request Description (中文)

你的功能请求是否与某个问题有关?请描述一下。
请对问题进行清晰扼要的描述。
newThread中默认模型可能会选择非chat模型。
image

请描述你希望的解决方案
优化默认模型选择的逻辑。

Summary by CodeRabbit

  • Bug Fixes
    • Improved the default model selection to prioritize chat and image generation models when starting a new thread, ensuring a more relevant model is chosen if no preference is set.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 17, 2025

Walkthrough

The code modifies the logic for selecting a default model in the NewThread component. Instead of picking the first model from the first enabled provider, it now selects the first model of type "Chat" or "ImageGeneration" from all enabled providers, using the model's own provider ID.

Changes

File(s) Change Summary
src/renderer/src/components/NewThread.vue Updated fallback model selection to choose the first chat or image generation model across all enabled providers, augmenting models with provider IDs.

Poem

In the meadow of code, a choice more precise,
The rabbit selects with logic concise.
From all the chat and image models it sees,
It picks the first with the greatest ease.
With provider in paw, and type in its sight,
The thread starts anew, and all feels right!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2ac58b and f1d9706.

📒 Files selected for processing (1)
  • src/renderer/src/components/NewThread.vue (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/NewThread.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-check (x64)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70dee84 and 5957096.

📒 Files selected for processing (1)
  • src/renderer/src/components/NewThread.vue (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-check (x64)

Comment on lines 233 to 241
const model = settingsStore.enabledModels
.flatMap(provider => provider.models)
.find(m => m.type === ModelType.Chat)
if (model) {
activeModel.value = {
name: model.name,
id: model.id,
providerId: settingsStore.enabledModels[0].providerId,
providerId: model.providerId,
tags: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

providerId can become undefined; selecting a model without its provider breaks thread creation

model.providerId is assumed to exist, but in every other place of the codebase the providerId is supplied by the provider wrapper, not by the MODEL_META itself (handleModelUpdate, previous loops, etc.).
If the meta objects in provider.models do not embed providerId, activeModel.value.providerId will be undefined, leading to:

  • createThread() receiving an invalid providerId
  • Model-icon lookup in the UI failing
  • Subsequent preference persistence writing an incomplete object

In addition, when no Chat-type model exists the watch leaves activeModel empty, later producing the same runtime failure.

-const model = settingsStore.enabledModels
-  .flatMap(provider => provider.models)
-  .find(m => m.type === ModelType.Chat)
-if (model) {
-  activeModel.value = {
-    name: model.name,
-    id: model.id,
-    providerId: model.providerId,
-    tags: []
-  }
+const record = settingsStore.enabledModels
+  .flatMap(p => p.models.map(m => ({ model: m, providerId: p.providerId })))
+  .find(r => r.model.type === ModelType.Chat)
+if (record) {
+  activeModel.value = {
+    name: record.model.name,
+    id: record.model.id,
+    providerId: record.providerId,
+    tags: []
+  }
+} else if (settingsStore.enabledModels.length) {
+  // graceful fallback – first available model of first provider
+  const p = settingsStore.enabledModels[0]
+  const m = p.models[0]
+  activeModel.value = {
+    name: m.name,
+    id: m.id,
+    providerId: p.providerId,
+    tags: []
+  }
 }

This preserves the provider context, prevents undefined values, and guarantees a fallback.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const model = settingsStore.enabledModels
.flatMap(provider => provider.models)
.find(m => m.type === ModelType.Chat)
if (model) {
activeModel.value = {
name: model.name,
id: model.id,
providerId: settingsStore.enabledModels[0].providerId,
providerId: model.providerId,
tags: []
const record = settingsStore.enabledModels
.flatMap(p => p.models.map(m => ({ model: m, providerId: p.providerId })))
.find(r => r.model.type === ModelType.Chat)
if (record) {
activeModel.value = {
name: record.model.name,
id: record.model.id,
providerId: record.providerId,
tags: []
}
} else if (settingsStore.enabledModels.length) {
// graceful fallback – first available model of first provider
const p = settingsStore.enabledModels[0]
const m = p.models[0]
activeModel.value = {
name: m.name,
id: m.id,
providerId: p.providerId,
tags: []
}
}
🤖 Prompt for AI Agents
In src/renderer/src/components/NewThread.vue around lines 233 to 241, the code
assigns activeModel.value.providerId directly from model.providerId, which can
be undefined because providerId is not embedded in model metadata but provided
by the provider wrapper. To fix this, retrieve providerId from the provider
object in the enabledModels array when selecting the model, ensuring providerId
is correctly assigned. Also, add a fallback to handle cases where no Chat-type
model exists to prevent activeModel from being empty and causing runtime errors.

.flatMap((provider) =>
provider.models.map((m) => ({ ...m, providerId: provider.providerId }))
)
.find((m) => m.type === ModelType.Chat)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModelType.ImageGeneration should also be selectable.

@zerob13
Copy link
Collaborator

zerob13 commented Jun 17, 2025

LGTM

@zerob13 zerob13 merged commit b6502f9 into ThinkInAIXYZ:dev Jun 17, 2025
2 checks passed
@hllshiro hllshiro deleted the fix-default-enable-model branch June 26, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants