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

feat(google-common): Gemini logprobs #7472

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

afirstenberg
Copy link
Contributor

Add support for OpenAI compatible logprobs, including:

  • logprobs boolean model parameter
  • topLogprobs numeric model parameter
  • logprobs returned in response_metadata in the same format OpenAI uses
  • updated documentation to indicate availability

Add support for token selection updates in model parameters:

  • presencePenalty
  • frequencyPenalty

Added tests for same.

  • Note that the tests for logprobs are essential since Google is highly restrictive on its use.
  • Note that the penalty test is somewhat non-deterministic

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 6, 2025
Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jan 9, 2025 11:59am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jan 9, 2025 11:59am

@afirstenberg afirstenberg changed the title feature(google-common): Gemini logprobs feat(google-common): Gemini logprobs Jan 6, 2025
@dosubot dosubot bot added auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features labels Jan 6, 2025
@@ -189,8 +189,16 @@ export abstract class ChatGoogleBase<AuthOptions>

topK = 40;

presencePenalty = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need to init as undefined - should have their actual typing

stopSequences: string[] = [];

logprobs: false;
Copy link
Collaborator

@jacoblee93 jacoblee93 Jan 9, 2025

Choose a reason for hiding this comment

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

This means that the only acceptable value is false

Did you mean to set logprobs = false?

and topLogprobs = 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh! Yeah. Thanks for catching this.

const topTokens: GeminiLogprobsTopCandidate[] =
logprobs?.topCandidates ?? [];
const content: Logprob[] = [];
for (let co = 0; co < chosenTokens.length; co += 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: what does co mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Counter. (Throwback to my BASIC days.)

Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

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

Thanks! Some nits

@afirstenberg
Copy link
Contributor Author

Fixed the type declarations. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:documentation Changes to documentation and examples, like .md, .rst, .ipynb files. Changes to the docs/ folder auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants