Skip to content

Commit

Permalink
[VertexAI] Add support for tools parameter (#1065)
Browse files Browse the repository at this point in the history
* [VertexAI] Add support for tools parameter

* Simplify tools parameter parsing and add support for passing parameters in model

---------

Co-authored-by: Nathan Sarrazin <[email protected]>
  • Loading branch information
ArthurGoupil and nsarrazin authored May 3, 2024
1 parent 5703512 commit 50febad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,12 @@ MODELS=`[
// Optional
"safetyThreshold": "BLOCK_MEDIUM_AND_ABOVE",
"apiEndpoint": "", // alternative api endpoint url
"apiEndpoint": "", // alternative api endpoint url,
"tools": [{
"googleSearchRetrieval": {
"disableAttribution": true
}
}]
}]
},
]`
Expand Down
12 changes: 8 additions & 4 deletions src/lib/server/endpoints/google/endpointVertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ export const endpointVertexParametersSchema = z.object({
HarmBlockThreshold.BLOCK_ONLY_HIGH,
])
.optional(),
tools: z.array(z.any()),
});

export function endpointVertex(input: z.input<typeof endpointVertexParametersSchema>): Endpoint {
const { project, location, model, apiEndpoint, safetyThreshold } =
const { project, location, model, apiEndpoint, safetyThreshold, tools } =
endpointVertexParametersSchema.parse(input);

const vertex_ai = new VertexAI({
Expand All @@ -39,6 +40,8 @@ export function endpointVertex(input: z.input<typeof endpointVertexParametersSch
});

return async ({ messages, preprompt, generateSettings }) => {
const parameters = { ...model.parameters, ...generateSettings };

const generativeModel = vertex_ai.getGenerativeModel({
model: model.id ?? model.name,
safetySettings: safetyThreshold
Expand Down Expand Up @@ -66,10 +69,11 @@ export function endpointVertex(input: z.input<typeof endpointVertexParametersSch
]
: undefined,
generationConfig: {
maxOutputTokens: generateSettings?.max_new_tokens ?? 4096,
stopSequences: generateSettings?.stop,
temperature: generateSettings?.temperature ?? 1,
maxOutputTokens: parameters?.max_new_tokens ?? 4096,
stopSequences: parameters?.stop,
temperature: parameters?.temperature ?? 1,
},
tools,
});

// Preprompt is the same as the first system message.
Expand Down

0 comments on commit 50febad

Please sign in to comment.