-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The
Analysis chainConstructor now correctly includes parameters for token pricing and context length, aligning with new features. Scripts ExecutedThe 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 |
||
|
||
/// <inheritdoc cref="GoogleAIModels.GeminiProVision" /> | ||
public class GeminiProVisionModel(GoogleProvider provider) | ||
: GoogleChatModel( | ||
provider, | ||
GoogleAIModels.GeminiProVision); | ||
GoogleAIModels.GeminiProVision, 32 * 1024, 0.5 * 0.000001, 1.5 * 0.000001); | ||
|
||
/// <inheritdoc cref="GoogleAIModels.GeminiProVision" /> | ||
public class Gemini15FlashModel(GoogleProvider provider) | ||
: GoogleChatModel( | ||
provider, | ||
GoogleAIModels.Gemini15Flash, 1024 * 1024, 0.35 * 0.000001, 1.05 * 0.000001, 0.70 * 0.000001, 2.1 * 0.000001); | ||
|
||
/// <inheritdoc cref="GoogleAIModels.GeminiProVision" /> | ||
public class Gemini15ProModel(GoogleProvider provider) | ||
: GoogleChatModel( | ||
provider, | ||
GoogleAIModels.Gemini15Flash, 2 * 1024 * 1024, 3.5 * 0.000001, 10.50 * 0.000001, 7.0 * 0.000001, 21.00 * 0.000001); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The
Locations that need attention:
These files should be updated to include the new assertions for token counts and pricing in their respective Analysis chainUpdated import and added assertions for token counts and pricing in the Also applies to: 17-17, 29-31 Scripts ExecutedThe 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 |
||
|
||
namespace LangChain.Providers.Google.Tests; | ||
|
||
|
@@ -13,7 +14,7 @@ public async Task GetWeather() | |
throw new InvalidOperationException("Gemini_API_Key is not set"); | ||
|
||
|
||
var model = new GoogleChatModel(apiKey, GoogleAIModels.GeminiPro); | ||
var model = new GeminiProModel(apiKey);//, GoogleAIModels.GeminiPro); | ||
|
||
var service = new WeatherService(); | ||
model.AddGlobalTools(service.AsGoogleFunctions(), service.AsGoogleCalls()); | ||
|
@@ -25,6 +26,9 @@ public async Task GetWeather() | |
"Sure! Could you please provide me with your location?".AsAiMessage(), | ||
"Dubai, UAE".AsHumanMessage(), | ||
}); | ||
response.Usage.InputTokens.Should().BeGreaterThan(0); | ||
response.Usage.OutputTokens.Should().BeGreaterThan(0); | ||
response.Usage.PriceInUsd.Should().BeGreaterThan(0); | ||
|
||
Console.WriteLine(response.Messages.AsHistory()); | ||
} | ||
|
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 theGoogleChatModel
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:
Length of output: 270
Script:
Length of output: 1163