Skip to content

Commit

Permalink
fix: __dirname should not be used in ES Module (#104)
Browse files Browse the repository at this point in the history
... instead of a relative image path (which didn't work with
`create-fabrice-ai` cloned example)

---------

Co-authored-by: Mike Grabowski <[email protected]>
  • Loading branch information
pkarw and grabbou authored Dec 12, 2024
1 parent 7e6c3b2 commit 5886455
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions example/src/ecommerce_product_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { agent } from 'fabrice-ai/agent'
import { teamwork } from 'fabrice-ai/teamwork'
import { logger } from 'fabrice-ai/telemetry'
import { solution, workflow } from 'fabrice-ai/workflow'
import path from 'path'

const techExpert = agent({
role: 'Technical expert',
Expand All @@ -27,7 +28,7 @@ const marketingManager = agent({
const productDescriptionWorkflow = workflow({
members: [techExpert, marketingManager],
description: `
Based on the picture './example/assets/example-sneakers.jpg' make the eCommerce product to
Based on the picture '${path.resolve(import.meta.dirname, '../assets/example-sneakers.jpg')}' make the eCommerce product to
list this product on the website.
Focus:
Expand All @@ -44,7 +45,6 @@ const productDescriptionWorkflow = workflow({
`,
snapshot: logger,
})

const result = await teamwork(productDescriptionWorkflow)

console.log(solution(result))
2 changes: 1 addition & 1 deletion example/src/library_photo_to_website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger } from 'fabrice-ai/telemetry'
import { solution, workflow } from 'fabrice-ai/workflow'
import path from 'path'

const workingDir = path.resolve(__dirname, '../assets/')
const workingDir = path.resolve(import.meta.dirname, '../assets/')

const { saveFile, readFile, listFilesFromDirectory } = createFileSystemTools({
workingDir,
Expand Down
7 changes: 1 addition & 6 deletions packages/create-fabrice-ai/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { execSync } from 'node:child_process'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { dirname } from 'node:path'
import { promises as Stream, Readable } from 'node:stream'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

import { extract } from 'tar'

Expand Down Expand Up @@ -58,6 +53,6 @@ export async function copyAdditionalTemplateFiles(root: string) {
]

for (const file of files) {
execSync(`cp ${path.join(__dirname, file.src)} ${path.join(root, file.dest)}`)
execSync(`cp ${path.join(import.meta.dirname, file.src)} ${path.join(root, file.dest)}`)
}
}
2 changes: 1 addition & 1 deletion packages/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ File system tools for reading, writing and listing files. The tools are sandboxe
```typescript
import { createFileSystemTools } from '@fabrice-ai/tools/filesystem'

const workingDir = path.resolve(__dirname, '../assets/')
const workingDir = path.resolve(import.meta.dirname, '../assets/')

const { saveFile, readFile, listFilesFromDirectory } = createFileSystemTools({
workingDir,
Expand Down

0 comments on commit 5886455

Please sign in to comment.