Skip to content

Commit 774570a

Browse files
authored
Add support for GCS FileData in inference (#8223)
1 parent 070e0cc commit 774570a

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

packages/vertexai/src/requests/request-helpers.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,33 @@ describe('request formatting methods', () => {
170170
],
171171
systemInstruction: { role: 'system', parts: [{ text: 'be excited' }] }
172172
});
173-
});
173+
}),
174+
it('formats fileData as part if provided as part', () => {
175+
const result = formatGenerateContentInput([
176+
'What is this?',
177+
{
178+
fileData: {
179+
mimeType: 'image/jpeg',
180+
fileUri: 'gs://sample.appspot.com/image.jpeg'
181+
}
182+
}
183+
]);
184+
expect(result).to.be.deep.equal({
185+
contents: [
186+
{
187+
role: 'user',
188+
parts: [
189+
{
190+
fileData: {
191+
mimeType: 'image/jpeg',
192+
fileUri: 'gs://sample.appspot.com/image.jpeg'
193+
}
194+
},
195+
{ text: 'What is this?' }
196+
]
197+
}
198+
]
199+
});
200+
});
174201
});
175202
});

packages/vertexai/src/types/content.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export type Part =
3434
| TextPart
3535
| InlineDataPart
3636
| FunctionCallPart
37-
| FunctionResponsePart;
37+
| FunctionResponsePart
38+
| FileDataPart;
3839

3940
/**
4041
* Content part interface if the part represents a text string.
@@ -101,6 +102,18 @@ export interface FunctionResponsePart {
101102
functionResponse: FunctionResponse;
102103
}
103104

105+
/**
106+
* Content part interface if the part represents {@link FileData}
107+
* @public
108+
*/
109+
export interface FileDataPart {
110+
text?: never;
111+
inlineData?: never;
112+
functionCall?: never;
113+
functionResponse?: never;
114+
fileData: FileData;
115+
}
116+
104117
/**
105118
* A predicted [FunctionCall] returned from the model
106119
* that contains a string representing the [FunctionDeclaration.name]
@@ -137,3 +150,12 @@ export interface GenerativeContentBlob {
137150
*/
138151
data: string;
139152
}
153+
154+
/**
155+
* Data pointing to a file uploaded on Google Cloud Storage.
156+
* @public
157+
*/
158+
export interface FileData {
159+
mimeType: string;
160+
fileUri: string;
161+
}

0 commit comments

Comments
 (0)