Skip to content

Commit 6b45998

Browse files
committed
Updated the code
1 parent 55cf945 commit 6b45998

File tree

4 files changed

+119
-4
lines changed

4 files changed

+119
-4
lines changed

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,59 @@ Commands:
405405
agents Return a list of agents
406406
models Return a list of models
407407
tools Return a list of tools
408-
download Download a model
408+
download Download a model (for Ollama)
409409
chat Start a chat session
410-
complete Complete a prompt
410+
complete Complete a prompt, generate image or speech from text
411411
embedding Generate an embedding
412412
version Print the version of this tool
413413
414414
Run "llm <command> --help" for more information on a command.
415415
```
416416

417+
### Prompt Completion
418+
419+
To have the model respond to a prompt, you can use the `complete` command. For example, to
420+
have the model respond to the prompt "What is the capital of France?" using the `claude-3-5-haiku-20241022`
421+
model, you can use the following command:
422+
423+
```bash
424+
llm complete "What is the capital of France?"
425+
```
426+
427+
The first time you use the command use the ``--model`` flag to specify the model you want to use. Your
428+
choice of model will be remembered for subsequent completions.
429+
430+
### Explain computer code
431+
432+
To have the model explain a piece of computer code, you can pipe the code into the `complete` command.
433+
For example, to have the model explain the code in the file `example.go`, you can use the following command:
434+
435+
```bash
436+
cat example.go | llm complete
437+
```
438+
439+
### Caption an image
440+
441+
To have the model generate a caption for an image, you can use the `complete` command with the `--file`
442+
flag. For example, to have the model generate a caption for the image in the file `example.jpg`, you can use
443+
the following command:
444+
445+
```bash
446+
llm complete --model gpt-4o --file picture.png "Explain this image"
447+
```
448+
449+
### Generate an image
450+
451+
To have the model generate an image from a prompt, you can use the `complete` command with the `--format image`
452+
option. For example, to have the model generate an image from the prompt "A picture of a cat", you can use
453+
the following command:
454+
455+
```bash
456+
llm complete --model dall-e-3 --format image "A picture of a cat"
457+
```
458+
459+
It will write the file in the current working directory.
460+
417461
## Contributing & Distribution
418462

419463
_This module is currently in development and subject to change_. Please do file

cmd/llm/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ type CLI struct {
7777
Tools ListToolsCmd `cmd:"" help:"Return a list of tools"`
7878

7979
// Commands
80-
Download DownloadModelCmd `cmd:"" help:"Download a model"`
80+
Download DownloadModelCmd `cmd:"" help:"Download a model (for Ollama)"`
8181
Chat ChatCmd `cmd:"" help:"Start a chat session"`
8282
Chat2 Chat2Cmd `cmd:"" help:"Start a chat session (2)"`
83-
Complete CompleteCmd `cmd:"" help:"Complete a prompt"`
83+
Complete CompleteCmd `cmd:"" help:"Complete a prompt, generate image or speech from text"`
8484
Embedding EmbeddingCmd `cmd:"" help:"Generate an embedding"`
8585
Version VersionCmd `cmd:"" help:"Print the version of this tool"`
8686
}

examples/image_generate/main.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/mutablelogic/go-llm"
9+
"github.com/mutablelogic/go-llm/pkg/openai"
10+
)
11+
12+
const (
13+
model = "dall-e-3"
14+
size = "1024x1024"
15+
quality = "standard"
16+
style = "vivid"
17+
)
18+
19+
func main() {
20+
// Create a new OpenAI agent
21+
agent, err := openai.New(os.Getenv("OPENAI_API_KEY"))
22+
if err != nil {
23+
panic(err)
24+
}
25+
26+
// Check args
27+
if len(os.Args) != 2 {
28+
fmt.Println("Usage: image_generate <caption>")
29+
os.Exit(-1)
30+
}
31+
32+
// Get a model
33+
model := agent.Model(context.TODO(), model)
34+
35+
// Get image
36+
images, err := model.Completion(
37+
context.TODO(),
38+
os.Args[1],
39+
llm.WithFormat("image"),
40+
llm.WithQuality(quality),
41+
llm.WithSize(size),
42+
llm.WithStyle(style),
43+
)
44+
if err != nil {
45+
panic(err)
46+
}
47+
48+
// Write out image(s)
49+
for i := 0; i < images.Num(); i++ {
50+
attachment := images.Attachment(i)
51+
if attachment == nil || attachment.Filename() == "" {
52+
continue
53+
}
54+
55+
// Create a file
56+
f, err := os.Create(attachment.Filename())
57+
if err != nil {
58+
panic(err)
59+
}
60+
defer f.Close()
61+
62+
// Write the image
63+
if _, err := f.Write(attachment.Data()); err != nil {
64+
panic(err)
65+
} else {
66+
fmt.Printf("%q written to %s\n", attachment.Caption(), attachment.Filename())
67+
}
68+
}
69+
70+
}

pkg/openai/audio.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package openai

0 commit comments

Comments
 (0)