-
Notifications
You must be signed in to change notification settings - Fork 167
beta wrap_gemini ts wrapper #2121
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
base: main
Are you sure you want to change the base?
Conversation
eb00750 to
15065e4
Compare
jacoblee93
left a comment
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.
Looks mostly good, some nits and questions
js/src/wrappers/gemini.ts
Outdated
| Object.assign(currentRun.extra.metadata.usage_metadata, usageMetadata); | ||
|
|
||
| // Fire-and-forget patch to persist changes asynchronously | ||
| currentRun.patchRun().catch(() => {}); |
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.
This is already backgrounded, just await it
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.
Actually - why do you need this at all?
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.
we need the usageMetadata to store in currentRun.extra.metadata.usage_metadata since that's new requirement from the DB team.
| openai-api-key: | ||
| description: "OpenAI API key" | ||
| required: false | ||
| gemini-api-key: |
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.
Is this populated in CI? I don't think so?
Let's just omit for now?
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.
oh, actually populated already; i added GEMINI_API_KEY in github action
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.
it is used for integration test of gemini wrapper
bc1edd1 to
11bbdeb
Compare
js/src/wrappers/gemini.ts
Outdated
| .map((chunk) => chunk.text) | ||
| .join(""); | ||
|
|
||
| const result: any = { |
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.
Try to avoid any, do you even need this cast?
js/src/wrappers/gemini.ts
Outdated
| // Add input token details if available | ||
| usageMetadata.input_token_details = { | ||
| ...(usage.cachedContentTokenCount && { | ||
| cache_read_over_200k: Math.max(0, usage.promptTokenCount - 200000), |
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.
The math here is a bit trickier I think - cache_read_over_200k and over_200k need to be mutually exclusive for our cost tracking to work out
e.g. if you had a 400k token prompt and 100k were cached the correct usage metadata would be:
{
input_tokens: 400000,
input_token_details: {
cache_read_over_200k: 100000,
over_200k: 300000,
}
}
At least that's my read based on: https://ai.google.dev/gemini-api/docs/pricing
We could ask for confirmation there?
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.
fixed
Adds beta TypeScript wrapper for Google Gemini API with automatic LangSmith tracing.
Features