Skip to content

Commit e26bea5

Browse files
improve help
1 parent 79b9cbd commit e26bea5

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,57 @@
1-
# File-for-AI
1+
# File-for-AI
22

33
File-for-AI is an open-source tool designed to compile all text files in a directory into a single file. This is particularly useful for preparing data to be added to AI models or chat GPT.
44

55
## Description
66

77
This tool traverses through a specified directory, reads all the text files (while ignoring non-text files and files specified in .gitignore), and compiles them into a single output file. This output file can then be used for various purposes such as training AI models or chat GPT.
88

9-
109
## Usage
1110

12-
Download the latest binary for the os of your coice from the [releases page](https://github.com/num30/file-for-ai/releases) it's under `Assets` section.
11+
Download the latest binary for the os of your coice from the [releases page](https://github.com/num30/file-for-ai/releases) under the `Assets` section.
12+
13+
To use this tool, you need to provide at least a directory path or a glob pattern as an argument. If an output file name is not provided, it will default to "file-for-ai.txt."
1314

14-
To use this tool, you need to provide at least a directory path as an argument. If an output file name is not provided, it will default to "file-for-ai.txt".
1515

16-
```bash
17-
file-for-ai <directory>
16+
``` bash
17+
file-for-ai <directory|pattern> [--output file]
1818
```
1919

2020
For example:
2121

22-
```bash
22+
``` bash
2323
file-for-ai /path/to/your/directory
2424
```
2525

2626
This will create a file named "file-for-ai.txt" in your current directory with the contents of all text files in the specified directory.
2727

28+
You can also use a glob pattern:
29+
30+
``` bash
31+
file-for-ai *.txt
32+
```
33+
34+
This will create a file named "file-for-ai.txt" in your current directory with the contents of all text files matching the pattern.
35+
36+
To specify a custom output file name:
37+
38+
``bash
39+
file-for-ai /path/to/your/directory --output custom-output.txt
40+
````
41+
42+
This will create a file named "custom-output.txt" in your current directory with the contents of all text files in the specified directory.
43+
2844
## Flags
45+
2946
The tool accepts the following flags:
3047
31-
- `--model` or `-m`: Specifies the model to use for toke counting. It should be one of the available models in [tiktoken-go](https://github.com/pkoukk/tiktoken-go?tab=readme-ov-file#available-encodings). Default is "gpt-4".
32-
- `--output` or `-o`: Specifies the name of the output file. Default is "file-for-ai.txt".
48+
- `--model`: Specifies the model to use for token counting. It should be one of the available models in [tiktoken-go](https://github.com/pkoukk/tiktoken-go?tab=readme-ov-file#available-encodings). Default is "gpt-4".
49+
- `--output`: Specifies the name of the output file. Default is "file-for-ai.txt."
50+
- `--ignore-gitignore`: If set to true, the tool will ignore the .gitignore file. Default is false.
51+
- `--process-non-text`: If set to true, the tool will process non-text files. Default is false.
3352
3453
For example:
3554
36-
``` bash
37-
file-for-ai /path/to/your/directory --model gpt-4o --output my-output.txt
38-
```
39-
40-
41-
This will create a file named "my-output.txt" in your current directory with the contents of all text files in the specified directory, token counting using the "gpt-4" model.
55+
``bash
56+
file-for-ai /path/to/your/directory --model gpt-4 --output my-output.txt
57+
```

main.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@ type Config struct {
1818
Model string `flag:"model" envvar:"MODEL" default:"gpt-4"`
1919
OutputFile string `flag:"output" envvar:"FILE" default:"file-for-ai.txt"`
2020
IgnoreGitIgnore bool `flag:"ignore-gitignore" envvar:"IGNORE_GITIGNORE" default:"false"`
21+
ProcessNonText bool `flag:"process-non-text" envvar:"PROCESS_NON_TEXT" default:"false"`
2122
}
2223

24+
var conf Config
25+
2326
func main() {
2427

25-
var conf Config
2628
err := config.NewConfReader("file-for-ai").Read(&conf)
2729
if err != nil {
2830
panic(err)
2931
}
3032

3133
if len(os.Args) < 2 {
3234
fmt.Println("Error: Directory path or glob pattern is required.")
33-
fmt.Println("Usage: file-for-ai <directory|pattern> [output file]")
35+
fmt.Println("Usage: file-for-ai <directory|pattern> --output [output file]")
36+
fmt.Println("\nExamples:")
37+
fmt.Println(" file-for-ai /path/to/directory")
38+
fmt.Println(" file-for-ai '*.txt'")
39+
fmt.Println(" file-for-ai /path/to/directory --output custom-output.txt")
3440
os.Exit(1)
3541
}
3642

@@ -126,7 +132,7 @@ func processFile(basePath, path string, info os.FileInfo, outputFile *os.File, t
126132
return err
127133
}
128134

129-
if !info.IsDir() && !isGitIgnored(relativePath, info.IsDir()) && isTextFile(path) && !strings.HasPrefix(path, ".") {
135+
if !info.IsDir() && !isGitIgnored(relativePath, info.IsDir()) && extensionBasedFilter(path) && !strings.HasPrefix(path, ".") {
130136
fileContents, err := os.ReadFile(path)
131137
if err != nil {
132138
fmt.Println("Error reading file:", path, err)
@@ -178,7 +184,11 @@ func isGitIgnored(path string, isDir bool) bool {
178184
return false
179185
}
180186

181-
func isTextFile(path string) bool {
187+
func extensionBasedFilter(path string) bool {
188+
if conf.ProcessNonText {
189+
return true
190+
}
191+
182192
ext := strings.ToLower(filepath.Ext(path))
183193
return !nonTextFileExtensions[ext]
184194
}

0 commit comments

Comments
 (0)