Skip to content

Commit 393c1ac

Browse files
committed
refactor: streamline ApiService methods and enhance VlmRun node
- Simplified the createAgent and getAgentDetail methods in ApiService for better readability. - Updated uploadUsingPresignedUrl to use a more descriptive method name, uploadToPresignedUrl. - Added agentPrompt parameter to VlmRun node for improved agent execution options. - Cleaned up code formatting for consistency and clarity.
1 parent 5631ebf commit 393c1ac

File tree

3 files changed

+59
-50
lines changed

3 files changed

+59
-50
lines changed

nodes/VlmRun/ApiService.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,30 @@ export class ApiService {
114114
};
115115
return client.agent.execute(request);
116116
}
117-
118-
static async createAgent(
119-
ef: IExecuteFunctions,
120-
prompt: string,
121-
): Promise<IDataObject> {
122-
const client = await this.initializeVlmRun(ef);
123-
const request: AgentCreateRequest = {
124-
config: {
125-
prompt,
126-
},
127-
};
128-
129-
return (await client.agent.create(request)) as unknown as IDataObject;
130-
}
131-
132-
static async getAgentDetail(
133-
ef: IExecuteFunctions,
134-
agentId: string,
135-
): Promise<IDataObject> {
136-
const client = await this.initializeVlmRun(ef);
137-
138-
return (await client.agent.detail(agentId)) as unknown as IDataObject;
139-
}
117+
118+
static async createAgent(ef: IExecuteFunctions, prompt: string): Promise<IDataObject> {
119+
const client = await this.initializeVlmRun(ef);
120+
const request: AgentCreateRequest = {
121+
config: {
122+
prompt,
123+
},
124+
};
125+
126+
return (await client.agent.create(request)) as unknown as IDataObject;
127+
}
128+
129+
static async getAgentDetail(ef: IExecuteFunctions, agentId: string): Promise<IDataObject> {
130+
const client = await this.initializeVlmRun(ef);
131+
132+
return (await client.agent.detail(agentId)) as unknown as IDataObject;
133+
}
140134

141135
static async uploadUsingPresignedUrl(
142136
ef: IExecuteFunctions,
143137
fileName: string,
144138
buffer: Buffer,
145-
purpose = 'assistants',
146-
expiration = 86400
139+
purpose = 'assistants',
140+
expiration = 86400,
147141
): Promise<{ url: string }> {
148142
const client = await this.initializeVlmRun(ef);
149143
const response = await client.agent.generatePresignedUrl({
@@ -152,7 +146,12 @@ export class ApiService {
152146
expiration,
153147
});
154148

155-
await client.agent.putImage({ url: response.url, buffer, fileName, contentType: response.content_type });
149+
await client.agent.uploadToPresignedUrl({
150+
url: response.url,
151+
buffer,
152+
fileName,
153+
contentType: response.content_type,
154+
});
156155

157156
return { url: response.preview_url };
158157
}

nodes/VlmRun/VlmRun.node.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ export class VlmRun implements INodeType {
121121
],
122122
default: 'list',
123123
},
124+
{
125+
displayName: 'Prompt',
126+
name: 'agentPrompt',
127+
type: 'string',
128+
typeOptions: {
129+
alwaysOpenEditWindow: false,
130+
rows: 4,
131+
},
132+
displayOptions: {
133+
show: {
134+
operation: ['executeAgent'],
135+
},
136+
},
137+
default: '',
138+
description: 'The prompt associated with the selected agent',
139+
},
124140
// File field for file upload operation
125141
{
126142
displayName: 'File',
@@ -153,22 +169,7 @@ export class VlmRun implements INodeType {
153169
description:
154170
'Domain to use for analysis. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
155171
},
156-
{
157-
displayName: 'Agent Prompt',
158-
name: 'agentPrompt',
159-
type: 'string',
160-
typeOptions: {
161-
alwaysOpenEditWindow: false,
162-
rows: 4,
163-
},
164-
displayOptions: {
165-
show: {
166-
operation: ['executeAgent'],
167-
},
168-
},
169-
default: '',
170-
description: 'The prompt associated with the selected agent',
171-
},
172+
172173
{
173174
displayName: 'Process Asynchronously',
174175
name: 'processAsynchronously',
@@ -277,15 +278,24 @@ export class VlmRun implements INodeType {
277278

278279
const file = this.getNodeParameter('file', i) as string;
279280
const { buffer, fileName } = await processFile(this, items[i], i, file);
280-
281-
const uploadRes = (await ApiService.uploadUsingPresignedUrl(this, fileName, buffer)) as IDataObject;
281+
282+
const uploadRes = (await ApiService.uploadUsingPresignedUrl(
283+
this,
284+
fileName,
285+
buffer,
286+
)) as IDataObject;
282287
const fileUrl = uploadRes.url as string;
283288

284289
if (!fileUrl) {
285290
throw new NodeOperationError(this.getNode(), 'Failed to obtain uploaded file URL');
286291
}
287-
288-
response = await ApiService.executeAgent(this, agentPrompt, { url: fileUrl }, callbackUrl);
292+
293+
response = await ApiService.executeAgent(
294+
this,
295+
agentPrompt,
296+
{ url: fileUrl },
297+
callbackUrl,
298+
);
289299
break;
290300
}
291301

nodes/VlmRun/VlmRunClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export interface AgentExecuteRequest {
5858
export interface AgentInfoResponse {
5959
id: string;
6060
name: string;
61-
version: string;
6261
description: string;
6362
prompt: string;
6463
json_schema?: any;
@@ -80,7 +79,6 @@ export interface AgentCreateRequest {
8079
export interface AgentCreateResponse {
8180
id: string;
8281
name: string;
83-
version: string;
8482
status: string;
8583
created_at: string;
8684
updated_at: string;
@@ -361,10 +359,12 @@ export class VlmRunClient {
361359
return this.makeAgentRequest('POST', '/files/presigned-url', request);
362360
},
363361

364-
putImage: async (request: AgentExecuteRequest): Promise<void> => {
362+
uploadToPresignedUrl: async (request: AgentExecuteRequest): Promise<void> => {
365363
const buff: Buffer = request.buffer as unknown as Buffer;
366364
const contentType: string =
367-
(request.contentType as string) || (request.buffer?.mimeType as string) || 'application/octet-stream';
365+
(request.contentType as string) ||
366+
(request.buffer?.mimeType as string) ||
367+
'application/octet-stream';
368368

369369
return this.ef.helpers.httpRequest.call(this.ef, {
370370
method: 'PUT',

0 commit comments

Comments
 (0)