Skip to content

Replace ?? with || in model fallback - #1210

Merged
isamu merged 1 commit into
receptron:mainfrom
isamu:llmModel
Aug 16, 2025
Merged

isamu merged 1 commit into
receptron:mainfrom
isamu:llmModel

Conversation

@isamu

@isamu isamu commented Aug 16, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Ensured default model is used when a blank or falsy value is provided, improving reliability for Anthropic and Gemini agents during chat initialization.
    • Prevents unexpected behavior caused by empty model inputs, aligning both agents’ fallback behavior.

@coderabbitai

coderabbitai Bot commented Aug 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Updated default model selection in two agent modules by replacing nullish coalescing (??) with logical OR (||), causing defaults to apply for any falsy model value. No changes to function signatures or other parameters.

Changes

Cohort / File(s) Change Summary
Anthropic agent defaulting
llm_agents/anthropic_agent/src/anthropic_agent.ts
Switched chatParams.model default from model ?? "claude-3-7-sonnet-20250219" to `model
Gemini agent defaulting
llm_agents/gemini_agent/src/gemini_agent.ts
Switched ModelParams.model default from model ?? "gemini-1.5-flash" to `model

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, flip a bit—
From ?? to ||, a tidy fit.
Empty strings now hop to norms,
Models set in safer forms.
Thump goes the log, defaults align—
A rabbit’s refactor, clean and fine. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
llm_agents/anthropic_agent/src/anthropic_agent.ts (3)

64-73: Guard against accidental JSON parse failures when response_format is enabled

If the model returns non-JSON text while maybeResponseFormat is true, JSON.parse will throw and fail the call. Safer to try/catch and fall back to null.

Apply:

-  const responseFormat = (() => {
-    if (maybeResponseFormat && text) {
-      const parsed = JSON.parse(text);
-      if (typeof parsed === "object" && parsed !== null) {
-        return parsed;
-      }
-    }
-    return null;
-  })();
+  const responseFormat = (() => {
+    if (maybeResponseFormat && text) {
+      try {
+        const parsed = JSON.parse(text);
+        if (typeof parsed === "object" && parsed !== null) {
+          return parsed;
+        }
+      } catch {
+        // non-JSON content; ignore and fall back
+      }
+    }
+    return null;
+  })();

236-238: Typo in error message: “Anthoropic” → “Anthropic”

Minor polish for error clarity.

-    throw new Error("Anthoropic no response");
+    throw new Error("Anthropic no response");

243-245: Harden JSON parsing for tool_use input assembly

A malformed or truncated stream could cause JSON.parse(partial) to throw, terminating the stream handling. A try/catch avoids taking down the whole request.

-    if (streamResponse.content[index].type === "tool_use") {
-      streamResponse.content[index].input = JSON.parse(partial);
-    }
+    if (streamResponse.content[index].type === "tool_use") {
+      try {
+        streamResponse.content[index].input = JSON.parse(partial);
+      } catch {
+        streamResponse.content[index].input = {};
+      }
+    }
llm_agents/gemini_agent/src/gemini_agent.ts (1)

239-242: Incorrect npm package listed for Gemini agent metadata

npms points to @anthropic-ai/sdk. This likely should be @google/generative-ai.

   license: "MIT",
   stream: true,
-  npms: ["@anthropic-ai/sdk"],
+  npms: ["@google/generative-ai"],
   environmentVariables: ["GOOGLE_GENAI_API_KEY"],
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4419b9e and a92a109.

📒 Files selected for processing (2)
  • llm_agents/anthropic_agent/src/anthropic_agent.ts (1 hunks)
  • llm_agents/gemini_agent/src/gemini_agent.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (24.x)
  • GitHub Check: build (22.x)
🔇 Additional comments (2)
llm_agents/anthropic_agent/src/anthropic_agent.ts (1)

161-168: Confirmed consistent || usage for model defaults across all agents

All TypeScript agents now use || for model defaulting, and no ?? patterns remain. This change aligns with the PR’s intent and ensures uniform defaulting semantics.

llm_agents/gemini_agent/src/gemini_agent.ts (1)

120-123: Consistent defaulting across all agents confirmed—LGTM

• Verified that every agent implementation uses || for model defaulting:

  • llm_agents/anthropic_agent/src/anthropic_agent.ts:161
  • llm_agents/openai_fetch_agent/src/openai_fetch_agent.ts:113
  • llm_agents/openai_agent/src/openai_image_agent.ts:36
  • llm_agents/openai_agent/src/openai_agent.ts:174
  • llm_agents/gemini_agent/src/gemini_agent.ts:121

No further changes needed—approving.

@isamu
isamu merged commit 8656f3a into receptron:main Aug 16, 2025
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.

1 participant