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

Configure the OpenAI user-agent for LangChain4J #733

Merged
merged 2 commits into from Mar 12, 2024

Conversation

jdubois
Copy link
Contributor

@jdubois jdubois commented Mar 11, 2024

This will give visibility to the LangChain4J project to Azure OpenAI and OpenAI.

WARNING I had to update OpenAI4j version to 0.15 and I don't know about the other impacts of this upgrade.

Summary by CodeRabbit

  • New Features
    • Enhanced API interactions by setting a default user agent across various models. This improves compatibility and monitoring with external services.

Copy link

coderabbitai bot commented Mar 11, 2024

Walkthrough

The update introduces a new constant, DEFAULT_USER_AGENT, across various models in the langchain4j-open-ai project. All primary models now incorporate this default user agent either directly in their constructors or through method chaining, ensuring a unified approach to setting user agents across the board.

Changes

Files Change Summary
.../model/openai/InternalOpenAiHelper.java Added DEFAULT_USER_AGENT constant.
.../model/openai/OpenAiChatModel.java
.../model/openai/OpenAiImageModel.java
.../model/openai/OpenAiLanguageModel.java
.../model/openai/OpenAiModerationModel.java
.../model/openai/OpenAiStreamingChatModel.java
Added setting of default user agent in the constructor.
.../model/openai/OpenAiEmbeddingModel.java
.../model/openai/OpenAiStreamingLanguageModel.java
Added method chaining call to set the user agent with default value.

🐇✨
In the land of code where the Java beans grow,
A constant was born, in the breeze it did flow.
DEFAULT_USER_AGENT, so sleek and so neat,
Across models it danced, on swift little feet.
🌟 With each constructor's call, and method's chain,
It whispered, "I'm here, to unify, to sustain."
🎉🐰 So here's to the changes, may they hop far and wide,
In the realm of Open AI, where the rabbits reside.

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a46fd20 and 21f19b8.
Files ignored due to path filters (1)
  • langchain4j-parent/pom.xml is excluded by: !**/*.xml
Files selected for processing (8)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/InternalOpenAiHelper.java (1 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiChatModel.java (1 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiEmbeddingModel.java (1 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiImageModel.java (2 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiLanguageModel.java (1 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiModerationModel.java (1 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiStreamingChatModel.java (1 hunks)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiStreamingLanguageModel.java (2 hunks)
Additional comments: 8
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiLanguageModel.java (1)
  • 63-63: Setting the DEFAULT_USER_AGENT in the OpenAiClient builder is a good practice for identifying the source of API requests. This change aligns with the PR's objective to enhance visibility to Azure OpenAI and OpenAI. Ensure that the DEFAULT_USER_AGENT value accurately represents the LangChain4J project and adheres to any user-agent formatting guidelines provided by OpenAI.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiModerationModel.java (1)
  • 65-65: Setting the DEFAULT_USER_AGENT in the OpenAiClient builder within the OpenAiModerationModel constructor is consistent with the PR's goal. This ensures that moderation requests from LangChain4J are properly identified by OpenAI. Good implementation.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiEmbeddingModel.java (1)
  • 71-71: The addition of the DEFAULT_USER_AGENT in the OpenAiEmbeddingModel constructor is in line with the PR's objectives. This ensures that embedding model requests are identifiable as coming from LangChain4J. This is a positive change for visibility and tracking purposes.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiStreamingLanguageModel.java (1)
  • 62-62: The inclusion of DEFAULT_USER_AGENT in the OpenAiStreamingLanguageModel constructor ensures that streaming language model requests can be traced back to LangChain4J. This aligns with the PR's aim to enhance project visibility to OpenAI services.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiImageModel.java (1)
  • 89-89: Incorporating the DEFAULT_USER_AGENT in the OpenAiImageModel constructor is a strategic move to ensure that image model requests from LangChain4J are identifiable by OpenAI. This change supports the PR's goal of improving visibility and is implemented correctly.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiChatModel.java (1)
  • 90-90: The addition of DEFAULT_USER_AGENT to the OpenAiChatModel constructor is a crucial step towards achieving the PR's objectives of enhancing LangChain4J's visibility to OpenAI. This ensures that chat model requests are properly identified, which is beneficial for tracking and optimization.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/OpenAiStreamingChatModel.java (1)
  • 87-87: The implementation of DEFAULT_USER_AGENT in the OpenAiStreamingChatModel constructor aligns with the PR's goal of enhancing the visibility of LangChain4J to OpenAI. This ensures that streaming chat model requests are identifiable, which is a positive change for tracking and visibility.
langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/InternalOpenAiHelper.java (1)
  • 37-37: The introduction of the DEFAULT_USER_AGENT constant in the InternalOpenAiHelper class is a key part of this PR, providing a centralized way to set the user-agent for all OpenAI API requests made by LangChain4J. This is a well-thought-out addition that supports the PR's objectives.

Copy link

@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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 21f19b8 and e241af1.
Files selected for processing (1)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/InternalOpenAiHelper.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • langchain4j-open-ai/src/main/java/dev/langchain4j/model/openai/InternalOpenAiHelper.java

Copy link
Owner

@langchain4j langchain4j left a comment

Choose a reason for hiding this comment

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

@jdubois thanks!

@langchain4j langchain4j merged commit 3aafa79 into langchain4j:main Mar 12, 2024
6 checks passed
@jdubois jdubois deleted the update-openai-user-agent branch March 12, 2024 07:04
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.

None yet

2 participants