mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 18:00:15 +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
|
|
@ -8,7 +8,12 @@
|
||||||
// mapModelToAzureConfig,
|
// mapModelToAzureConfig,
|
||||||
// } = require('librechat-data-provider');
|
// } = require('librechat-data-provider');
|
||||||
const { Callback } = require('@librechat/agents');
|
const { Callback } = require('@librechat/agents');
|
||||||
const { providerEndpointMap, removeNullishValues } = require('librechat-data-provider');
|
const {
|
||||||
|
providerEndpointMap,
|
||||||
|
removeNullishValues,
|
||||||
|
EModelEndpoint,
|
||||||
|
parseCompactConvo,
|
||||||
|
} = require('librechat-data-provider');
|
||||||
const {
|
const {
|
||||||
extractBaseURL,
|
extractBaseURL,
|
||||||
// constructAzureURL,
|
// constructAzureURL,
|
||||||
|
|
@ -27,6 +32,10 @@ const { logger } = require('~/config');
|
||||||
|
|
||||||
/** @typedef {import('@librechat/agents').MessageContentComplex} MessageContentComplex */
|
/** @typedef {import('@librechat/agents').MessageContentComplex} MessageContentComplex */
|
||||||
|
|
||||||
|
const providerSchemas = {
|
||||||
|
[EModelEndpoint.bedrock]: true,
|
||||||
|
};
|
||||||
|
|
||||||
class AgentClient extends BaseClient {
|
class AgentClient extends BaseClient {
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
@ -119,6 +128,26 @@ class AgentClient extends BaseClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSaveOptions() {
|
getSaveOptions() {
|
||||||
|
const hasSchema = providerSchemas[this.options.endpoint];
|
||||||
|
let runOptions =
|
||||||
|
this.options.endpoint === EModelEndpoint.agents
|
||||||
|
? {
|
||||||
|
model: undefined,
|
||||||
|
// TODO:
|
||||||
|
// would need to be override settings; otherwise, model needs to be undefined
|
||||||
|
// model: this.override.model,
|
||||||
|
// instructions: this.override.instructions,
|
||||||
|
// additional_instructions: this.override.additional_instructions,
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
|
if (hasSchema) {
|
||||||
|
runOptions = parseCompactConvo({
|
||||||
|
endpoint: this.options.endpoint,
|
||||||
|
conversation: this.modelOptions,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return removeNullishValues(
|
return removeNullishValues(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
|
|
@ -129,15 +158,8 @@ class AgentClient extends BaseClient {
|
||||||
imageDetail: this.options.imageDetail,
|
imageDetail: this.options.imageDetail,
|
||||||
spec: this.options.spec,
|
spec: this.options.spec,
|
||||||
},
|
},
|
||||||
this.modelOptions,
|
// TODO: PARSE OPTIONS BY PROVIDER, MAY CONTAIN SENSITIVE DATA
|
||||||
{
|
runOptions,
|
||||||
model: undefined,
|
|
||||||
// TODO:
|
|
||||||
// would need to be override settings; otherwise, model needs to be undefined
|
|
||||||
// model: this.override.model,
|
|
||||||
// instructions: this.override.instructions,
|
|
||||||
// additional_instructions: this.override.additional_instructions,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
assistantSchema,
|
assistantSchema,
|
||||||
gptPluginsSchema,
|
gptPluginsSchema,
|
||||||
// agentsSchema,
|
// agentsSchema,
|
||||||
|
bedrockInputSchema,
|
||||||
compactAgentsSchema,
|
compactAgentsSchema,
|
||||||
compactOpenAISchema,
|
compactOpenAISchema,
|
||||||
compactGoogleSchema,
|
compactGoogleSchema,
|
||||||
|
|
@ -32,7 +33,7 @@ type EndpointSchema =
|
||||||
| typeof gptPluginsSchema
|
| typeof gptPluginsSchema
|
||||||
| typeof assistantSchema
|
| typeof assistantSchema
|
||||||
| typeof compactAgentsSchema
|
| typeof compactAgentsSchema
|
||||||
| typeof compactAgentsSchema;
|
| typeof bedrockInputSchema;
|
||||||
|
|
||||||
const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
||||||
[EModelEndpoint.openAI]: openAISchema,
|
[EModelEndpoint.openAI]: openAISchema,
|
||||||
|
|
@ -46,7 +47,7 @@ const endpointSchemas: Record<EModelEndpoint, EndpointSchema> = {
|
||||||
[EModelEndpoint.assistants]: assistantSchema,
|
[EModelEndpoint.assistants]: assistantSchema,
|
||||||
[EModelEndpoint.azureAssistants]: assistantSchema,
|
[EModelEndpoint.azureAssistants]: assistantSchema,
|
||||||
[EModelEndpoint.agents]: compactAgentsSchema,
|
[EModelEndpoint.agents]: compactAgentsSchema,
|
||||||
[EModelEndpoint.bedrock]: compactAgentsSchema,
|
[EModelEndpoint.bedrock]: bedrockInputSchema,
|
||||||
};
|
};
|
||||||
|
|
||||||
// const schemaCreators: Record<EModelEndpoint, (customSchema: DefaultSchemaValues) => EndpointSchema> = {
|
// const schemaCreators: Record<EModelEndpoint, (customSchema: DefaultSchemaValues) => EndpointSchema> = {
|
||||||
|
|
@ -305,6 +306,7 @@ type CompactEndpointSchema =
|
||||||
| typeof bingAISchema
|
| typeof bingAISchema
|
||||||
| typeof compactAnthropicSchema
|
| typeof compactAnthropicSchema
|
||||||
| typeof compactChatGPTSchema
|
| typeof compactChatGPTSchema
|
||||||
|
| typeof bedrockInputSchema
|
||||||
| typeof compactPluginsSchema;
|
| typeof compactPluginsSchema;
|
||||||
|
|
||||||
const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
||||||
|
|
@ -315,7 +317,7 @@ const compactEndpointSchemas: Record<string, CompactEndpointSchema> = {
|
||||||
[EModelEndpoint.azureAssistants]: compactAssistantSchema,
|
[EModelEndpoint.azureAssistants]: compactAssistantSchema,
|
||||||
[EModelEndpoint.agents]: compactAgentsSchema,
|
[EModelEndpoint.agents]: compactAgentsSchema,
|
||||||
[EModelEndpoint.google]: compactGoogleSchema,
|
[EModelEndpoint.google]: compactGoogleSchema,
|
||||||
[EModelEndpoint.bedrock]: compactAgentsSchema,
|
[EModelEndpoint.bedrock]: bedrockInputSchema,
|
||||||
/* BingAI needs all fields */
|
/* BingAI needs all fields */
|
||||||
[EModelEndpoint.bingAI]: bingAISchema,
|
[EModelEndpoint.bingAI]: bingAISchema,
|
||||||
[EModelEndpoint.anthropic]: compactAnthropicSchema,
|
[EModelEndpoint.anthropic]: compactAnthropicSchema,
|
||||||
|
|
|
||||||
|
|
@ -435,6 +435,25 @@ export const coerceNumber = z.union([z.number(), z.string()]).transform((val) =>
|
||||||
return 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({
|
export const tConversationSchema = z.object({
|
||||||
conversationId: z.string().nullable(),
|
conversationId: z.string().nullable(),
|
||||||
endpoint: eModelEndpointSchema.nullable(),
|
endpoint: eModelEndpointSchema.nullable(),
|
||||||
|
|
@ -477,6 +496,9 @@ export const tConversationSchema = z.object({
|
||||||
assistant_id: z.string().optional(),
|
assistant_id: z.string().optional(),
|
||||||
/* agents */
|
/* agents */
|
||||||
agent_id: z.string().optional(),
|
agent_id: z.string().optional(),
|
||||||
|
/* AWS Bedrock */
|
||||||
|
maxTokens: z.number().optional(),
|
||||||
|
additionalModelRequestFields: DocumentType.optional(),
|
||||||
/* assistant + agents */
|
/* assistant + agents */
|
||||||
instructions: z.string().optional(),
|
instructions: z.string().optional(),
|
||||||
additional_instructions: z.string().optional(),
|
additional_instructions: z.string().optional(),
|
||||||
|
|
@ -975,19 +997,6 @@ export const agentsSchema = tConversationSchema
|
||||||
maxContextTokens: undefined,
|
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
|
export const compactOpenAISchema = tConversationSchema
|
||||||
.pick({
|
.pick({
|
||||||
model: true,
|
model: true,
|
||||||
|
|
@ -1172,3 +1181,38 @@ export const compactPluginsSchema = tConversationSchema
|
||||||
return removeNullishValues(newObj);
|
return removeNullishValues(newObj);
|
||||||
})
|
})
|
||||||
.catch(() => ({}));
|
.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