Skip to content

Add support for GCS FileData in inference #8223

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

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
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
29 changes: 28 additions & 1 deletion packages/vertexai/src/requests/request-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ describe('request formatting methods', () => {
],
systemInstruction: { role: 'system', parts: [{ text: 'be excited' }] }
});
});
}),
it('formats fileData as part if provided as part', () => {
const result = formatGenerateContentInput([
'What is this?',
{
fileData: {
mimeType: 'image/jpeg',
fileUri: 'gs://sample.appspot.com/image.jpeg'
}
}
]);
expect(result).to.be.deep.equal({
contents: [
{
role: 'user',
parts: [
{
fileData: {
mimeType: 'image/jpeg',
fileUri: 'gs://sample.appspot.com/image.jpeg'
}
},
{ text: 'What is this?' }
]
}
]
});
});
});
});
24 changes: 23 additions & 1 deletion packages/vertexai/src/types/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export type Part =
| TextPart
| InlineDataPart
| FunctionCallPart
| FunctionResponsePart;
| FunctionResponsePart
| FileDataPart;

/**
* Content part interface if the part represents a text string.
Expand Down Expand Up @@ -101,6 +102,18 @@ export interface FunctionResponsePart {
functionResponse: FunctionResponse;
}

/**
* Content part interface if the part represents {@link FileData}
* @public
*/
export interface FileDataPart {
text?: never;
inlineData?: never;
functionCall?: never;
functionResponse?: never;
fileData: FileData;
}

/**
* A predicted [FunctionCall] returned from the model
* that contains a string representing the [FunctionDeclaration.name]
Expand Down Expand Up @@ -137,3 +150,12 @@ export interface GenerativeContentBlob {
*/
data: string;
}

/**
* Data pointing to a file uploaded on Google Cloud Storage.
* @public
*/
export interface FileData {
mimeType: string;
fileUri: string;
}
Loading