Skip to content

Commit

Permalink
fix(attachments): use file names instead of ids (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Radek Ježek <[email protected]>
  • Loading branch information
jezekra1 authored Oct 20, 2024
1 parent 4a0b9ee commit bfb2962
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/runs/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { LoadedRun } from '@/runs/execution/types.js';
import { UserResource } from '@/tools/entities/tool-resources/user-resource.entity.js';
import { SystemResource } from '@/tools/entities/tool-resources/system-resource.entity.js';
import { BEE_OBSERVE_API_AUTH_KEY, BEE_OBSERVE_API_URL } from '@/config.js';
import { Attachment } from '@/messages/attachment.entity';

const agentExecutionTime = new Summary({
name: 'agent_execution_time_seconds',
Expand Down Expand Up @@ -80,7 +81,7 @@ export async function executeRun(run: LoadedRun) {
(message) =>
new BaseMessage(
message.role,
`${message.content}${message.attachments && message.attachments.length > 0 ? `\n\nFiles:\n${message.attachments.map((attachment) => attachment.file.id).join('\n')}` : ''}`,
`${message.content}${message.attachments && message.attachments.length > 0 ? `\n\nFiles:\n${message.attachments.map((attachment) => (attachment as Loaded<Attachment, 'file'>).file.$.filename).join('\n')}` : ''}`,
{
createdAt: message.createdAt
}
Expand Down
22 changes: 11 additions & 11 deletions src/runs/execution/tools/read-file-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ export class ReadFileTool extends Tool<StringToolOutput, ReadFileToolOptions> {
description = 'Retrieve file content.';
inputSchema() {
return z.object({
id:
filename:
this.options.files.length === 1
? z
.literal(this.options.files[0].id)
.describe(`Id of the file with name ${this.options.files[0].filename}`)
? z.literal(this.options.files[0].filename).describe(`Name of the file to read`)
: z
.union(
this.options.files.map((file) =>
z.literal(file.id).describe(`Id of the file with name ${file.filename}`)
) as [ZodLiteral<string>, ZodLiteral<string>, ...ZodLiteral<string>[]]
this.options.files.map((file) => z.literal(file.filename)) as [
ZodLiteral<string>,
ZodLiteral<string>,
...ZodLiteral<string>[]
]
)
.describe('File id.')
.describe('Name of the file to read.')
});
}

protected async _run({ id }: ToolInput<ReadFileTool>): Promise<StringToolOutput> {
const file = this.options.files.find((file) => file.id === id);
protected async _run({ filename }: ToolInput<ReadFileTool>): Promise<StringToolOutput> {
const file = this.options.files.find((file) => file.filename === filename);
if (!file) {
throw new ToolError(`File ${id} not found.`);
throw new ToolError(`File ${filename} not found.`);
}
try {
const fileObject = await getExtractedFileObject(file);
Expand Down

0 comments on commit bfb2962

Please sign in to comment.