-
Notifications
You must be signed in to change notification settings - Fork 3
feat(google): support streaming #114
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ export class GoogleVertexProvider extends DefaultProviderProxy { | |||||
| if (!path) { | ||||||
| return { error: 'Unable to parse path' } | ||||||
| } | ||||||
| return `${this.providerProxy.baseUrl}${path}` | ||||||
| return `${stripTrailingSlash(this.providerProxy.baseUrl)}/${stripLeadingSlash(path)}` | ||||||
| } else { | ||||||
| return { error: 'baseUrl is required for the Google Provider' } | ||||||
| } | ||||||
|
|
@@ -72,7 +72,8 @@ export class GoogleVertexProvider extends DefaultProviderProxy { | |||||
| this.flavor = 'anthropic' | ||||||
| } | ||||||
|
|
||||||
| return `/${version}/projects/${projectId}/locations/${region}/publishers/${publisher}/models/${modelAndApi}` | ||||||
| const path = `/${version}/projects/${projectId}/locations/${region}/publishers/${publisher}/models/${modelAndApi}` | ||||||
| return path | ||||||
| } | ||||||
|
|
||||||
| async prepRequest() { | ||||||
|
|
@@ -92,7 +93,7 @@ export class GoogleVertexProvider extends DefaultProviderProxy { | |||||
| } | ||||||
|
|
||||||
| async requestHeaders(headers: Headers): Promise<void> { | ||||||
| const token = await authToken(this.providerProxy.credentials, this.options.kv) | ||||||
| const token = await authToken(this.providerProxy.credentials, this.options.kv, this.options.subFetch) | ||||||
| headers.set('Authorization', `Bearer ${token}`) | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -104,10 +105,9 @@ export class GoogleVertexProvider extends DefaultProviderProxy { | |||||
| * @param url - The URL to extract the region from e.g. https://europe-west4-aiplatform.googleapis.com or https://aiplatform.googleapis.com. | ||||||
| */ | ||||||
| function regionFromUrl(url: string): null | string { | ||||||
| if (url.includes('https://aiplatform.googleapis.com')) { | ||||||
| return 'global' | ||||||
| } | ||||||
| // The group includes regions with hyphen like "europe-west4" | ||||||
| const match = url.match(/^https:\/\/(.+?)-aiplatform\.googleapis\.com$/) | ||||||
| return match?.[1] ?? null | ||||||
| const match = url.match(/^https:\/\/([^-]+)-aiplatform\.googleapis\.com$/) | ||||||
|
||||||
| const match = url.match(/^https:\/\/([^-]+)-aiplatform\.googleapis\.com$/) | |
| const match = url.match(/^https:\/\/([a-z0-9-]+)-aiplatform\.googleapis\.com$/) |
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 TODO comment correctly identifies a bug: for streaming responses, usage from multiple chunks should be accumulated rather than overwritten. Each chunk may contain partial usage data that needs to be summed. Consider implementing accumulation logic similar to how token counts are typically aggregated across streaming chunks.