-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat(GoogleGemini): added api usage with costs #316
Conversation
WalkthroughThis update primarily focuses on enhancing the Google Generative AI integration by upgrading the package version and refining various functionalities. Key changes include modifying the Changes
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- src/Directory.Packages.props (1 hunks)
- src/Providers/Google/src/Extensions/GoogleGeminiExtensions.cs (1 hunks)
- src/Providers/Google/src/GoogleChatModel.cs (5 hunks)
- src/Providers/Google/src/Predefined/GeminiModels.cs (1 hunks)
- src/Providers/Google/test/Tests.cs (3 hunks)
Files skipped from review due to trivial changes (2)
- src/Directory.Packages.props
- src/Providers/Google/src/Extensions/GoogleGeminiExtensions.cs
Additional comments not posted (5)
src/Providers/Google/src/Predefined/GeminiModels.cs (3)
21-21
: Constructor now correctly includes parameters for token pricing and context length, aligning with new features.
27-27
: Constructor now correctly includes parameters for token pricing and context length, aligning with new features.
15-15
: Constructor now correctly includes parameters for token pricing and context length, aligning with new features.src/Providers/Google/src/GoogleChatModel.cs (2)
213-228
: TheGetUsage
method now correctly calculates usage based on the new token pricing parameters, aligning with new features.Verification successful
The
rg
command output shows multiple instances of theGetUsage
method across different files and models. To ensure the correct usage of the new parameters, we need to focus on the instances withinGoogleChatModel.cs
.
The instances of
GetUsage
inGoogleChatModel.cs
show that the method is being used correctly with the new parameters. TheGetUsage
method is called, and the resultingUsage
object is modified with additional properties likeTime
before being added to the usage tracking.
GetUsage
is called withresponse
and the resultingUsage
object is modified withTime = watch.Elapsed
.- The modified
Usage
object is then added to the usage tracking viaAddUsage(usage2)
andprovider.AddUsage(usage2)
.This confirms that the integration of the
GetUsage
method with other components is correct and aligns with the new token pricing parameters.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify integration of `GetUsage` method with other components. # Test: Search for the usage of `GetUsage` method. Expect: Correct usage of new parameters. rg --type csharp $'GetUsage'Length of output: 1608
Script:
#!/bin/bash # Description: Review instances of `GetUsage` in `GoogleChatModel.cs` to verify correct usage of new parameters. # Extract lines around the usage of `GetUsage` in `GoogleChatModel.cs` rg --type csharp --context 5 'GetUsage' src/Providers/Google/src/GoogleChatModel.csLength of output: 1261
230-243
: TheCalculatePriceInUsd
method now includes logic for calculating prices based on the new token pricing parameters, aligning with new features.Verification successful
The
CalculatePriceInUsd
method is correctly integrated with the new parameters across different files.
OpenAiChatModel.cs
: The method is called withoutputTokens
andinputTokens
parameters.GoogleChatModel.cs
: The method is called withoutputTokens
andinputTokens
parameters.ApiHelpers.cs
: The method is implemented with a different signature but is used correctly.AnthropicModel.cs
: The method is called withoutputTokens
andinputTokens
parameters.IPaidLargeLanguageModel.cs
: The method is declared with the correct parameters.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify integration of `CalculatePriceInUsd` method with other components. # Test: Search for the usage of `CalculatePriceInUsd` method. Expect: Correct usage of new parameters. rg --type csharp $'CalculatePriceInUsd'Length of output: 1098
Script:
#!/bin/bash # Extract the context of `CalculatePriceInUsd` usage in OpenAiChatModel.cs rg --context 5 'CalculatePriceInUsd' src/Providers/OpenAI/src/Chat/OpenAiChatModel.cs # Extract the context of `CalculatePriceInUsd` usage in GoogleChatModel.cs rg --context 5 'CalculatePriceInUsd' src/Providers/Google/src/GoogleChatModel.cs # Extract the context of `CalculatePriceInUsd` usage in ApiHelpers.cs rg --context 5 'CalculatePriceInUsd' src/Providers/Anthropic/libs/Anthropic/Helpers/ApiHelpers.cs # Extract the context of `CalculatePriceInUsd` usage in AnthropicModel.cs rg --context 5 'CalculatePriceInUsd' src/Providers/Anthropic/libs/Anthropic/AnthropicModel.cs # Extract the context of `CalculatePriceInUsd` usage in IPaidLargeLanguageModel.cs rg --context 5 'CalculatePriceInUsd' src/Providers/Abstractions/src/Chat/IPaidLargeLanguageModel.csLength of output: 3316
@@ -6,10 +6,22 @@ namespace LangChain.Providers.Google.Predefined; | |||
public class GeminiProModel(GoogleProvider provider) | |||
: GoogleChatModel( | |||
provider, | |||
GoogleAIModels.GeminiPro); | |||
GoogleAIModels.GeminiPro, 32 * 1024, 0.5 * 0.000001, 1.5 * 0.000001); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The GeminiProModel
constructor calls in GenerativeModelTests.cs
and Tests.cs
do not include the new parameters for token pricing and context length. Please update these test files to reflect the changes in the constructor.
src/Providers/Google/test/GenerativeModelTests.cs
src/Providers/Google/test/Tests.cs
Analysis chain
Constructor now correctly includes parameters for token pricing and context length, aligning with new features.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify integration of `GeminiProModel` with other components.
# Test: Search for the usage of `GeminiProModel` constructor. Expect: Correct usage of new parameters.
rg --type csharp $'new GeminiProModel'
Length of output: 252
Script:
#!/bin/bash
# Extract lines around the usage of `GeminiProModel` constructor in `GenerativeModelTests.cs`
rg --context 5 'new GeminiProModel' src/Providers/Google/test/GenerativeModelTests.cs
# Extract lines around the usage of `GeminiProModel` constructor in `Tests.cs`
rg --context 5 'new GeminiProModel' src/Providers/Google/test/Tests.cs
Length of output: 1181
@@ -1,4 +1,5 @@ | |||
using GenerativeAI.Models; | |||
using GeminiProModel = LangChain.Providers.Google.Predefined.GeminiProModel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The GetWeather
method implementations across different providers have been successfully extracted. The Google
provider's test method includes the new assertions for token counts and pricing, which aligns with the PR objectives. However, the other providers' test methods do not include these new assertions.
- Google Provider: The
GetWeather
method includes assertions forInputTokens
andOutputTokens
. - Other Providers: The
GetWeather
methods do not include the new assertions for token counts and pricing.
Locations that need attention:
src/Providers/TogetherAI/tests/Tests.cs
src/Providers/OpenRouter/tests/Tests.cs
src/Providers/OpenAI/test/Tests.cs
src/Providers/DeepInfra/tests/Tests.cs
src/Providers/Anthropic/tests/Tests.cs
These files should be updated to include the new assertions for token counts and pricing in their respective GetWeather
methods.
Analysis chain
Updated import and added assertions for token counts and pricing in the GetWeather
test method align with the new features.
Also applies to: 17-17, 29-31
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify integration of `GetWeather` test method with other components.
# Test: Search for the usage of `GetWeather` method. Expect: Correct usage of new assertions.
rg --type csharp $'GetWeather'
Length of output: 467
Script:
#!/bin/bash
# Extract the implementation of the `GetWeather` method from each identified file.
# Define the pattern to match the `GetWeather` method.
pattern=$'public async Task GetWeather() { $$$ }'
# Search and extract the `GetWeather` method implementations.
ast-grep --lang csharp --pattern "$pattern" src/Providers/TogetherAI/tests/Tests.cs
ast-grep --lang csharp --pattern "$pattern" src/Providers/OpenRouter/tests/Tests.cs
ast-grep --lang csharp --pattern "$pattern" src/Providers/OpenAI/test/Tests.cs
ast-grep --lang csharp --pattern "$pattern" src/Providers/Google/test/Tests.cs
ast-grep --lang csharp --pattern "$pattern" src/Providers/DeepInfra/tests/Tests.cs
ast-grep --lang csharp --pattern "$pattern" src/Providers/Anthropic/tests/Tests.cs
Length of output: 734
Script:
#!/bin/bash
# Extract the implementation of the `GetWeather` method from each identified file.
# Define a more flexible pattern to match the `GetWeather` method.
pattern=$'public async Task GetWeather() { $$$ }'
# Search and extract the `GetWeather` method implementations.
ast-grep --lang csharp --pattern 'public async Task GetWeather() { $$$ }' src/Providers/TogetherAI/tests/Tests.cs
ast-grep --lang csharp --pattern 'public async Task GetWeather() { $$$ }' src/Providers/OpenRouter/tests/Tests.cs
ast-grep --lang csharp --pattern 'public async Task GetWeather() { $$$ }' src/Providers/OpenAI/test/Tests.cs
ast-grep --lang csharp --pattern 'public async Task GetWeather() { $$$ }' src/Providers/Google/test/Tests.cs
ast-grep --lang csharp --pattern 'public async Task GetWeather() { $$$ }' src/Providers/DeepInfra/tests/Tests.cs
ast-grep --lang csharp --pattern 'public async Task GetWeather() { $$$ }' src/Providers/Anthropic/tests/Tests.cs
Length of output: 734
Script:
#!/bin/bash
# Extract the implementation of the `GetWeather` method from each identified file using a more general approach.
# Search for the `GetWeather` method and extract surrounding lines.
rg 'public async Task GetWeather' -A 20 src/Providers/TogetherAI/tests/Tests.cs
rg 'public async Task GetWeather' -A 20 src/Providers/OpenRouter/tests/Tests.cs
rg 'public async Task GetWeather' -A 20 src/Providers/OpenAI/test/Tests.cs
rg 'public async Task GetWeather' -A 20 src/Providers/Google/test/Tests.cs
rg 'public async Task GetWeather' -A 20 src/Providers/DeepInfra/tests/Tests.cs
rg 'public async Task GetWeather' -A 20 src/Providers/Anthropic/tests/Tests.cs
Length of output: 5376
string id, | ||
int contextLength = 0, | ||
double inputTokenPriceUsd = 0, | ||
double outputTokenPriceUsd = 0, | ||
double secondaryInputTokenPrice = 0, | ||
double secondaryOutputTokenPrice = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Constructor calls in src/Providers/Google/test/Tests.cs
do not include the new parameters for token pricing and context length. Please update the test cases to reflect the changes in the GoogleChatModel
constructor.
src/Providers/Google/test/Tests.cs
: Lines wherenew GoogleChatModel
is called.
Analysis chain
Constructor now correctly includes parameters for token pricing and context length, aligning with new features.
Also applies to: 23-23
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify integration of `GoogleChatModel` constructor with other components.
# Test: Search for the usage of `GoogleChatModel` constructor. Expect: Correct usage of new parameters.
rg --type csharp $'new GoogleChatModel'
Length of output: 270
Script:
#!/bin/bash
# Extract and review the relevant lines from `src/Providers/Google/test/Tests.cs` to verify the usage of new parameters in `GoogleChatModel` constructor.
# Display lines around the constructor usage to check parameter usage.
rg --type csharp --context 5 'new GoogleChatModel' src/Providers/Google/test/Tests.cs
Length of output: 1163
Sweep: PR ReviewAuthors of pull request: @gunpal5 src/Directory.Packages.propsUpdated the version of the "Google_GenerativeAI" package from "0.1.20" to "1.0.0". Sweep Found These Issues
LangChain/src/Directory.Packages.props Line 22 in 40f8aa9
View Diff src/Providers/Google/src/Extensions/GoogleGeminiExtensions.csRemoved the custom serialization context for the Sweep Found These Issues
View Diff src/Providers/Google/src/GoogleChatModel.csAdded configurable parameters to the Sweep Found These Issues
LangChain/src/Providers/Google/src/GoogleChatModel.cs Lines 230 to 242 in 40f8aa9
View Diff LangChain/src/Providers/Google/src/GoogleChatModel.cs Lines 213 to 227 in 40f8aa9
View Diff LangChain/src/Providers/Google/src/GoogleChatModel.cs Lines 230 to 242 in 40f8aa9
View Diff Potential IssuesSweep isn't 100% sure if the following are issues or not but they may be worth taking a look at.
LangChain/src/Providers/Google/src/GoogleChatModel.cs Lines 230 to 243 in 40f8aa9
View Diff src/Providers/Google/src/Predefined/GeminiModels.csAdded new parameters to existing model constructors and introduced two new model classes with specific configurations. Sweep Found These Issues
LangChain/src/Providers/Google/src/Predefined/GeminiModels.cs Lines 24 to 27 in 40f8aa9
View Diff LangChain/src/Providers/Google/src/Predefined/GeminiModels.cs Lines 17 to 21 in 40f8aa9
View Diff src/Providers/Google/test/Tests.csReplaced Potential IssuesSweep isn't 100% sure if the following are issues or not but they may be worth taking a look at.
View Diff |
Summary by CodeRabbit
New Features
Google_GenerativeAI
package, enhancing overall functionality and capabilities.GoogleChatModel
with new parameters for context length and token prices, providing more detailed usage and cost calculations.Improvements
GoogleGeminiExtensions
, improving performance and maintainability.Tests
GeminiProModel
and added assertions forInputTokens
,OutputTokens
, andPriceInUsd
for improved test coverage.