mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-08 19:48:51 +01:00
WIP: agent provider schema parsing
This commit is contained in:
parent
11eb215922
commit
16106e0969
3 changed files with 94 additions and 26 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
assistantSchema,
|
||||
gptPluginsSchema,
|
||||
// agentsSchema,
|
||||
bedrockInputSchema,
|
||||
compactAgentsSchema,
|
||||
compactOpenAISchema,
|
||||
compactGoogleSchema,
|
||||
|
|
@ -32,7 +33,7 @@ type EndpointSchema =
|
|||
| typeof gptPluginsSchema
|
||||
| typeof assistantSchema
|
||||
| typeof compactAgentsSchema
|
||||
| typeof compactAgentsSchema;
|
||||
| typeof bedrockInputSchema;
|
||||
|
||||
const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
||||
[EModelEndpoint.openAI]: openAISchema,
|
||||
|
|
@ -46,7 +47,7 @@ const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
|||
[EModelEndpoint.assistants]: assistantSchema,
|
||||
[EModelEndpoint.azureAssistants]: assistantSchema,
|
||||
[EModelEndpoint.agents]: compactAgentsSchema,
|
||||
[EModelEndpoint.bedrock]: compactAgentsSchema,
|
||||
[EModelEndpoint.bedrock]: bedrockInputSchema,
|
||||
};
|
||||
|
||||
// const schemaCreators: Record<EModelEndpoint, (customSchema: DefaultSchemaValues) => EndpointSchema> = {
|
||||
|
|
@ -305,6 +306,7 @@ type CompactEndpointSchema =
|
|||
| typeof bingAISchema
|
||||
| typeof compactAnthropicSchema
|
||||
| typeof compactChatGPTSchema
|
||||
| typeof bedrockInputSchema
|
||||
| typeof compactPluginsSchema;
|
||||
|
||||
const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
||||
|
|
@ -315,7 +317,7 @@ const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
|||
[EModelEndpoint.azureAssistants]: compactAssistantSchema,
|
||||
[EModelEndpoint.agents]: compactAgentsSchema,
|
||||
[EModelEndpoint.google]: compactGoogleSchema,
|
||||
[EModelEndpoint.bedrock]: compactAgentsSchema,
|
||||
[EModelEndpoint.bedrock]: bedrockInputSchema,
|
||||
/* BingAI needs all fields */
|
||||
[EModelEndpoint.bingAI]: bingAISchema,
|
||||
[EModelEndpoint.anthropic]: compactAnthropicSchema,
|
||||
|
|
|
|||
|
|
@ -435,6 +435,25 @@ export const coerceNumber = z.union([z.number(), z.string()]).transform((val) =>
|
|||
return val;
|
||||
});
|
||||
|
||||
type DocumentTypeValue =
|
||||
| null
|
||||
| boolean
|
||||
| number
|
||||
| string
|
||||
| DocumentTypeValue[]
|
||||
| { [key: string]: DocumentTypeValue };
|
||||
|
||||
const DocumentType: z.ZodType<DocumentTypeValue> = z.lazy(() =>
|
||||
z.union([
|
||||
z.null(),
|
||||
z.boolean(),
|
||||
z.number(),
|
||||
z.string(),
|
||||
z.array(z.lazy(() => DocumentType)),
|
||||
z.record(z.lazy(() => DocumentType)),
|
||||
]),
|
||||
);
|
||||
|
||||
export const tConversationSchema = z.object({
|
||||
conversationId: z.string().nullable(),
|
||||
endpoint: eModelEndpointSchema.nullable(),
|
||||
|
|
@ -477,6 +496,9 @@ export const tConversationSchema = z.object({
|
|||
assistant_id: z.string().optional(),
|
||||
/* agents */
|
||||
agent_id: z.string().optional(),
|
||||
/* AWS Bedrock */
|
||||
maxTokens: z.number().optional(),
|
||||
additionalModelRequestFields: DocumentType.optional(),
|
||||
/* assistant + agents */
|
||||
instructions: z.string().optional(),
|
||||
additional_instructions: z.string().optional(),
|
||||
|
|
@ -975,19 +997,6 @@ export const agentsSchema = tConversationSchema
|
|||
maxContextTokens: undefined,
|
||||
}));
|
||||
|
||||
export const compactAgentsSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
agent_id: true,
|
||||
instructions: true,
|
||||
promptPrefix: true,
|
||||
iconURL: true,
|
||||
greeting: true,
|
||||
spec: true,
|
||||
})
|
||||
.transform(removeNullishValues)
|
||||
.catch(() => ({}));
|
||||
|
||||
export const compactOpenAISchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
|
|
@ -1172,3 +1181,38 @@ export const compactPluginsSchema = tConversationSchema
|
|||
return removeNullishValues(newObj);
|
||||
})
|
||||
.catch(() => ({}));
|
||||
|
||||
export const compactAgentsSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
agent_id: true,
|
||||
instructions: true,
|
||||
additional_instructions: true,
|
||||
iconURL: true,
|
||||
greeting: true,
|
||||
spec: true,
|
||||
})
|
||||
.transform(removeNullishValues)
|
||||
.catch(() => ({}));
|
||||
|
||||
export const bedrockInputSchema = tConversationSchema
|
||||
.pick({
|
||||
/* LibreChat parameters */
|
||||
instructions: true,
|
||||
additional_instructions: true,
|
||||
iconURL: true,
|
||||
greeting: true,
|
||||
spec: true,
|
||||
maxOutputTokens: true,
|
||||
/* shared parameters */
|
||||
additionalModelRequestFields: true,
|
||||
model: true,
|
||||
maxTokens: true,
|
||||
temperature: true,
|
||||
topP: true,
|
||||
stop: true,
|
||||
})
|
||||
.transform(removeNullishValues)
|
||||
.catch(() => ({}));
|
||||
|
||||
export type BedrockConverseInput = z.infer<typeof bedrockInputSchema>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue