Skip to content
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

LLM: Add support for JSON mode #102

Merged
merged 2 commits into from
May 4, 2024
Merged

LLM: Add support for JSON mode #102

merged 2 commits into from
May 4, 2024

Conversation

Hialus
Copy link
Member

@Hialus Hialus commented May 4, 2024

We need JSON mode for the file selector pipeline.

Summary by CodeRabbit

  • New Features
    • Added a new response format option in chat functionalities, allowing users to choose between text and JSON formats for their interactions.
  • Enhancements
    • Integrated a new vendor, OpenAI, enhancing the backend support for chat functionalities.
    • Enabled JSON mode by default in certain processes to improve data handling efficiency.

@Hialus Hialus self-assigned this May 4, 2024
Copy link
Contributor

coderabbitai bot commented May 4, 2024

Walkthrough

The recent updates across the application aim to enhance flexibility in output formatting by introducing a new response_format parameter in key components. These changes include accommodating different response formats like TEXT and JSON. The adjustments in the CompletionArguments class, OpenAIChatModel method, and file_selector_pipeline align the application with these new formatting capabilities.

Changes

File Change Summary
.../completion_arguments.py Added response_format parameter to CompletionArguments class constructor with default "TEXT".
.../external/openai_chat.py Added response_format parameter to chat method in OpenAIChatModel.
.../chat/file_selector_pipeline.py Added vendor="OpenAI", json_mode=True to RequirementList, and response_format="JSON" to CompletionArguments.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 650a448 and b999023.
Files selected for processing (1)
  • app/llm/external/ollama.py (2 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

kaancayli
kaancayli previously approved these changes May 4, 2024
Copy link
Contributor

@kaancayli kaancayli left a comment

Choose a reason for hiding this comment

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

Code LGTM

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: 2

Out of diff range and nitpick comments (1)
app/llm/completion_arguments.py (1)

14-19: Add a docstring entry for the new response_format parameter to improve code documentation.

app/pipeline/chat/file_selector_pipeline.py Show resolved Hide resolved
app/llm/external/openai_chat.py Show resolved Hide resolved
@Hialus Hialus merged commit e95f0da into main May 4, 2024
5 checks passed
@Hialus Hialus deleted the feature/llm/json-mode branch May 4, 2024 12:29
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: 2

@@ -93,6 +93,7 @@ def complete(
model=self.model,
prompt=prompt,
images=[image.base64] if image else None,
format="json" if arguments.response_format == "JSON" else "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification script has confirmed that the handling of the response_format in the complete method of the OllamaModel class only explicitly sets the format to "json" when the response_format is "JSON". For all other cases, it defaults to an empty string. This could potentially lead to issues if other formats are expected to be handled but are not explicitly set.

Given this information, it is clear that the handling of non-JSON formats might not be adequately addressed, which aligns with the initial concern raised in the review comment. Therefore, it is recommended to ensure that all necessary formats are explicitly handled or a default format is set.

Action Required: Review and adjust the handling of response formats in the complete method.

  • Ensure that all expected formats are explicitly handled.
  • Consider setting a default format if the response_format does not match "JSON".
Analysis chain

Ensure handling of non-JSON formats in the complete method.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify handling of non-JSON formats in the `complete` method.

# Test: Search for handling of non-JSON formats in the `complete` method. Expect: Explicit handling or default setting.
rg --type py $'format="[^"]*" if arguments.response_format == "JSON" else ""'

Length of output: 280

@@ -103,6 +104,7 @@
response = self._client.chat(
model=self.model,
messages=convert_to_ollama_messages(messages),
format="json" if arguments.response_format == "JSON" else "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification script was designed to check how non-JSON formats are handled in the chat method by searching for the conditional logic that sets the format variable. The script specifically looked for instances where the format is set to "json" if the response_format is "JSON", otherwise it sets an empty string.

Analysis of Script Results:

The script found two occurrences in app/llm/external/ollama.py where the format is set based on the condition provided. Both lines are identical, suggesting that the handling of the response_format is consistent within the file. However, the script's output indicates that non-JSON formats are not explicitly handled, as the format defaults to an empty string if the response_format is not "JSON".

Conclusion:

The review comment raised a concern about the handling of non-JSON formats, suggesting that there should be explicit handling or a default setting for formats other than JSON. The script results confirm that the code does not handle non-JSON formats explicitly and defaults to an empty string, which aligns with the concern expressed in the review comment.

Given this information, the review comment is accurate in pointing out the lack of explicit handling for non-JSON formats. Therefore, the appropriate response is to confirm the issue identified in the review comment.


Handling of Non-JSON Formats in the chat Method Needs Attention

The verification process confirmed that the chat method in app/llm/external/ollama.py does not explicitly handle non-JSON response formats. Currently, if the response_format is not "JSON", the format is set to an empty string, which might not be the intended behavior for all use cases. It is recommended to implement explicit handling or set a sensible default for non-JSON formats.

  • File: app/llm/external/ollama.py
  • Issue: Non-JSON formats default to an empty string, which may not be appropriate for all scenarios.
Analysis chain

Ensure handling of non-JSON formats in the chat method.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify handling of non-JSON formats in the `chat` method.

# Test: Search for handling of non-JSON formats in the `chat` method. Expect: Explicit handling or default setting.
rg --type py $'format="[^"]*" if arguments.response_format == "JSON" else ""'

Length of output: 280

Copy link
Contributor

@yassinsws yassinsws left a comment

Choose a reason for hiding this comment

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

Code LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants