Skip to content

Commit

Permalink
🤖 fix: Address Minor Agent Issues (#4483)
Browse files Browse the repository at this point in the history
* fix(Agents): remove test code in openAI/llm.js

* refactor: add use of enums in encodeAndFormat

* fix: image attachment payload formatting for agents

* chore: imports
  • Loading branch information
danny-avila authored Oct 21, 2024
1 parent a6fbe75 commit ec92298
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/server/controllers/agents/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const { Callback, createMetadataAggregator } = require('@librechat/agents');
const {
Constants,
VisionModes,
openAISchema,
EModelEndpoint,
anthropicSchema,
Expand Down Expand Up @@ -196,6 +197,7 @@ class AgentClient extends BaseClient {
this.options.req,
attachments,
this.options.agent.provider,
VisionModes.agents,
);
message.image_urls = image_urls.length ? image_urls : undefined;
return files;
Expand Down
2 changes: 1 addition & 1 deletion api/server/services/Endpoints/openAI/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const initializeClient = async ({
if (optionsOnly) {
const requestOptions = Object.assign(
{
modelOptions: endpointOption.modelOptions,
modelOptions: endpointOption.model_parameters,
},
clientOptions,
);
Expand Down
1 change: 0 additions & 1 deletion api/server/services/Endpoints/openAI/llm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function getLLMConfig(apiKey, options = {}) {
} = options;

let llmConfig = {
model: 'gpt-4o-mini',
streaming,
};

Expand Down
20 changes: 16 additions & 4 deletions api/server/services/Files/images/encode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const axios = require('axios');
const { EModelEndpoint, FileSources, VisionModes } = require('librechat-data-provider');
const { getStrategyFunctions } = require('../strategies');
const {
FileSources,
VisionModes,
ImageDetail,
ContentTypes,
EModelEndpoint,
} = require('librechat-data-provider');
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { logger } = require('~/config');

/**
Expand Down Expand Up @@ -79,7 +85,7 @@ async function encodeAndFormat(req, files, endpoint, mode) {
promises.push(preparePayload(req, file));
}

const detail = req.body.imageDetail ?? 'auto';
const detail = req.body.imageDetail ?? ImageDetail.auto;

/** @type {Array<[MongoFile, string]>} */
const formattedImages = await Promise.all(promises);
Expand All @@ -104,7 +110,7 @@ async function encodeAndFormat(req, files, endpoint, mode) {
}

const imagePart = {
type: 'image_url',
type: ContentTypes.IMAGE_URL,
image_url: {
url: imageContent.startsWith('http')
? imageContent
Expand All @@ -113,6 +119,12 @@ async function encodeAndFormat(req, files, endpoint, mode) {
},
};

if (mode === VisionModes.agents) {
result.image_urls.push(imagePart);
result.files.push(fileMetadata);
continue;
}

if (endpoint && endpoint === EModelEndpoint.google && mode === VisionModes.generative) {
delete imagePart.image_url;
imagePart.inlineData = {
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ export const visionModels = [
];
export enum VisionModes {
generative = 'generative',
agents = 'agents',
}

export function validateVisionModel({
Expand Down

0 comments on commit ec92298

Please sign in to comment.