Skip to content

VinF Hybrid Inference: flatten request contents rather than plucking the first #8991

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

Open
wants to merge 1 commit into
base: vaihi-exp-google-ai
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/vertexai/src/methods/chrome-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ export class ChromeAdapter {
*/
async generateContent(request: GenerateContentRequest): Promise<Response> {
const session = await this.createSession();
// TODO: support multiple content objects when Chrome supports
// NOTE: assumes all parts are from the same role, enforced by isOnDeviceRequest validation.
// TODO: stop stripping roles when Chrome supports
// sequence<LanguageModelMessage>
const contents = await Promise.all(
request.contents[0].parts.map(ChromeAdapter.toLanguageModelMessageContent)
request.contents.flatMap(content =>
content.parts.map(ChromeAdapter.toLanguageModelMessageContent)
)
);
const text = await session.prompt(contents);
return ChromeAdapter.toResponse(text);
Expand All @@ -113,10 +116,13 @@ export class ChromeAdapter {
request: GenerateContentRequest
): Promise<Response> {
const session = await this.createSession();
// TODO: support multiple content objects when Chrome supports
// NOTE: assumes all parts are from the same role, enforced by isOnDeviceRequest validation.
// TODO: stop stripping roles when Chrome supports
// sequence<LanguageModelMessage>
const contents = await Promise.all(
request.contents[0].parts.map(ChromeAdapter.toLanguageModelMessageContent)
request.contents.flatMap(content =>
content.parts.map(ChromeAdapter.toLanguageModelMessageContent)
)
);
const stream = await session.promptStreaming(contents);
return ChromeAdapter.toStreamResponse(stream);
Expand Down
Loading