-
Notifications
You must be signed in to change notification settings - Fork 354
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
Support for Google's Vertex AI #265
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5d30f4c
support vertex ai
flexchar 6392d10
use standard methods
flexchar 1547882
support streaming for Vertex AI
flexchar d774ee9
remove obsolete methods on the chunk
flexchar f82669e
Merge branch 'main' into #10-support-vertex-ai
flexchar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ProviderAPIConfig } from '../types'; | ||
|
||
// Good reference for using REST: https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#gemini-beginner-samples-drest | ||
// Difference versus Studio AI: https://cloud.google.com/vertex-ai/docs/start/ai-platform-users | ||
export const GoogleApiConfig: ProviderAPIConfig = { | ||
getBaseURL: ({ providerOptions }) => { | ||
const { vertexProjectId, vertexRegion } = providerOptions; | ||
|
||
return `https://${vertexRegion}-aiplatform.googleapis.com/v1/projects/${vertexProjectId}/locations/${vertexRegion}/publishers/google`; | ||
}, | ||
headers: ({ providerOptions }) => { | ||
const { apiKey } = providerOptions; | ||
|
||
return { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}; | ||
}, | ||
getEndpoint: ({ fn, gatewayRequestBody }) => { | ||
let mappedFn = fn; | ||
const { model, stream } = gatewayRequestBody; | ||
if (stream) { | ||
mappedFn = `stream-${fn}`; | ||
} | ||
switch (mappedFn) { | ||
case 'chatComplete': { | ||
return `/models/${model}:generateContent`; | ||
} | ||
case 'stream-chatComplete': { | ||
return `/models/${model}:streamGenerateContent`; | ||
} | ||
|
||
// Embed API is not yet implemented in the gateway | ||
// This may be as easy as copy-paste from Google provider, but needs to be tested | ||
|
||
default: | ||
return ''; | ||
} | ||
}, | ||
}; | ||
|
||
export default GoogleApiConfig; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Vertex allows to send
?alt=sse
in url to get SSE instead of json stream. I think that will make things easy for us. Should we make that change?