Skip to content

Commit 226fcf5

Browse files
authored
Merge pull request #9 from zeke/support-filenames-as-input
support filenames as input
2 parents 81fd609 + 95e693e commit 226fcf5

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ $ yolox "add 100px white padding around dots.png and save it as dots-with-room.p
2929
# convert dots.png -bordercolor white -border 100 dots-with-room.png
3030
```
3131

32+
You can also pass a file containing the prompt. This lets you write long prompts and iterate on them without retyping:
33+
34+
```
35+
echo "do some stuff" > PROMPT.md
36+
$ yolox PROMPT.md
37+
```
38+
3239
## Caution
3340

3441
This tool should be used with caution. It's called "YOLO X" because it's dangerous. **yolo** as in "you only live once" and *x* as in "execute this code". It lets an AI write code for you, then blindly executes that code on your system. There are a few guardrails in its prompt to prevent the result from taking destructive actions like deleting files or directories, but there's always still a danger that the resulting commands will have unintended consequences. You've been warned!
@@ -47,6 +54,10 @@ npx yolox@latest "use ffmpeg to convert foo.mkv to foo.mp4"
4754

4855
## Usage
4956

57+
```
58+
yolox <prompt-string-or-filename-containing-prompt-string>
59+
```
60+
5061
yolox supports [GPT4o](https://openai.com/index/hello-gpt-4o/) on OpenAI and [Llama 3](https://replicate.com/meta/meta-llama-3-70b-instruct) on Replicate.
5162

5263
To add support for other models or providers, [open a pull request](https://github.com/zeke/yolox/issues)!

index.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import { spawn } from 'node:child_process'
44
import minimist from 'minimist'
55
import { createClient } from './client.js'
66

7+
import { readFile } from 'node:fs/promises'
8+
import { existsSync } from 'node:fs'
9+
import { resolve } from 'node:path'
10+
711
const argv = minimist(process.argv.slice(2))
8-
const englishCommand = argv._.join(' ')
12+
let englishCommand = argv._.join(' ')
913
const model = argv.model || 'gpt-4o'
1014

1115
const models = {
@@ -28,6 +32,18 @@ if (!models[model]) {
2832
process.exit()
2933
}
3034

35+
if (englishCommand && !englishCommand.includes(' ')) {
36+
const filePath = resolve(process.cwd(), englishCommand)
37+
if (existsSync(filePath)) {
38+
try {
39+
englishCommand = (await readFile(filePath, 'utf8')).trim()
40+
} catch (error) {
41+
console.error(`Error reading file: ${error.message}`)
42+
process.exit(1)
43+
}
44+
}
45+
}
46+
3147
const provider = models[model].split(':')[0]
3248
const modelFullName = models[model].split(':')[1]
3349
const client = createClient(provider)
@@ -76,9 +92,13 @@ child.stderr.on('data', (data) => {
7692
})
7793

7894
child.on('error', (error) => {
79-
console.error(`Error executing command: ${error.message}`)
95+
console.error(`\nError executing command: ${error.message}`)
8096
})
8197

8298
child.on('close', (code) => {
83-
console.log(`Child process exited with code ${code}`)
99+
if (code === 0) {
100+
console.log(`\n✅ Success! Child process exited with code ${code}`)
101+
} else {
102+
console.log(`\n❌ Error! Child process exited with code ${code}`)
103+
}
84104
})

0 commit comments

Comments
 (0)