Skip to content

Commit 2c9fed2

Browse files
committed
Improve usage examples
1 parent 9c52fc7 commit 2c9fed2

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

README.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,42 @@ A developer-friendly Lua interface for working with multiple generative AI provi
2121

2222
## Usage
2323

24-
### Minimal
25-
2624
```lua
2725
local AI = require("src.ai")
2826

2927
local ai = AI.new("<YOUR_API_KEY>", "https://api.openai.com/v1/chat/completions")
30-
local chat = ai:chat("gpt-4o-mini")
28+
```
3129

30+
### Minimal
31+
32+
```lua
33+
local chat = ai:chat("gpt-4o-mini")
3234
print(chat:say("Hello, world!"))
3335
```
3436

3537
### Streaming
3638

3739
```lua
38-
local AI = require("src.ai")
39-
40-
local ai = AI.new("<YOUR_API_KEY>", "https://api.openai.com/v1/chat/completions")
4140
local chat = ai:chat("gpt-4o-mini", { settings = { stream = true } })
42-
4341
chat:say("Hello, world!")
4442
```
4543

4644
### JSON
4745

4846
```lua
49-
local AI = require("src.ai")
50-
local ai = AI.new("<YOUR_API_KEY>", "https://api.openai.com/v1/chat/completions")
51-
52-
local response_schema = {
47+
local npc_schema = {
5348
name = { type = "string" },
49+
class = { type = "string" },
5450
level = { type = "integer" },
5551
}
5652

57-
local chat = ai:chat("gpt-4o-mini", {
58-
settings = {
59-
json = {
60-
title = "NPC",
61-
description = "A non-player character's attributes.",
62-
schema = response_schema,
63-
},
64-
},
65-
})
53+
local json_object = {
54+
title = "NPC",
55+
description = "A non-player character's attributes.",
56+
schema = npc_schema,
57+
}
6658

59+
local chat = ai:chat("gpt-4o-mini", { settings = { json = json_object } })
6760
print(chat:say("Create a powerful wizard called Torben."))
6861
```
6962

0 commit comments

Comments
 (0)