🤖 feat: Custom Endpoint Agents (experimental) (#4627)

* wip: first pass, custom endpoint agents

* chore: imports

* chore: consolidate exports

* fix: imports

* feat: convert message.content array to strings for legacy format handling (deepseek/groq)

* refactor: normalize ollama endpoint name

* refactor: update mocking in isDomainAllowed.spec.js

* refactor: update deepseekModels in tokens.js and tokens.spec.js
This commit is contained in:
Danny Avila 2024-11-04 12:59:04 -05:00 committed by GitHub
parent 9437e95315
commit 2e519f9b57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 230 additions and 73 deletions

View file

@ -13,6 +13,7 @@ const {
VisionModes,
openAISchema,
EModelEndpoint,
KnownEndpoints,
anthropicSchema,
bedrockOutputParser,
removeNullishValues,
@ -25,6 +26,7 @@ const {
const {
formatMessage,
formatAgentMessages,
formatContentStrings,
createContextHandlers,
} = require('~/app/clients/prompts');
const { encodeAndFormat } = require('~/server/services/Files/images/encode');
@ -44,6 +46,8 @@ const providerParsers = {
[EModelEndpoint.bedrock]: bedrockOutputParser,
};
const legacyContentEndpoints = new Set([KnownEndpoints.groq, KnownEndpoints.deepseek]);
class AgentClient extends BaseClient {
constructor(options = {}) {
super(null, options);
@ -74,6 +78,7 @@ class AgentClient extends BaseClient {
this.collectedUsage = collectedUsage;
/** @type {ArtifactPromises} */
this.artifactPromises = artifactPromises;
/** @type {AgentClientOptions} */
this.options = Object.assign({ endpoint: options.endpoint }, clientOptions);
}
@ -478,6 +483,9 @@ class AgentClient extends BaseClient {
this.run = run;
const messages = formatAgentMessages(payload);
if (legacyContentEndpoints.has(this.options.agent.endpoint)) {
formatContentStrings(messages);
}
await run.processStream({ messages }, config, {
[Callback.TOOL_ERROR]: (graph, error, toolId) => {
logger.error(