@@ -21,49 +21,42 @@ A developer-friendly Lua interface for working with multiple generative AI provi
21
21
22
22
## Usage
23
23
24
- ### Minimal
25
-
26
24
``` lua
27
25
local AI = require (" src.ai" )
28
26
29
27
local ai = AI .new (" <YOUR_API_KEY>" , " https://api.openai.com/v1/chat/completions" )
30
- local chat = ai : chat ( " gpt-4o-mini " )
28
+ ```
31
29
30
+ ### Minimal
31
+
32
+ ``` lua
33
+ local chat = ai :chat (" gpt-4o-mini" )
32
34
print (chat :say (" Hello, world!" ))
33
35
```
34
36
35
37
### Streaming
36
38
37
39
``` lua
38
- local AI = require (" src.ai" )
39
-
40
- local ai = AI .new (" <YOUR_API_KEY>" , " https://api.openai.com/v1/chat/completions" )
41
40
local chat = ai :chat (" gpt-4o-mini" , { settings = { stream = true } })
42
-
43
41
chat :say (" Hello, world!" )
44
42
```
45
43
46
44
### JSON
47
45
48
46
``` 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 = {
53
48
name = { type = " string" },
49
+ class = { type = " string" },
54
50
level = { type = " integer" },
55
51
}
56
52
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
+ }
66
58
59
+ local chat = ai :chat (" gpt-4o-mini" , { settings = { json = json_object } })
67
60
print (chat :say (" Create a powerful wizard called Torben." ))
68
61
```
69
62
0 commit comments