Skip to content

Commit cf022af

Browse files
committed
add: example completion patterns to readme
1 parent 39a9538 commit cf022af

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Package openai provides a Go SDK for the OpenAI API.this package supports severa
33
models. You can specify the desired model using the `Model` field in the request object.
44

55

6-
## Support API
6+
## Feature
77

88
- ChatGPT (GPT-3, GPT-3.5, GPT-4)
99
- DALL·E 2
@@ -12,6 +12,7 @@ models. You can specify the desired model using the `Model` field in the request
1212
- Fine-Tune
1313
- File
1414
- Moderations
15+
- Completion Patterns
1516

1617
## Install ![Go Version](https://img.shields.io/badge/go%20version-%3E=1.19-61CFDD.svg?style=flat-square)
1718

@@ -55,6 +56,47 @@ func main() {
5556

5657
```
5758

59+
Example Completion Patterns
60+
61+
```go
62+
package main
63+
64+
import (
65+
"context"
66+
"github.com/GoFarsi/openai"
67+
"github.com/GoFarsi/openai/client"
68+
"github.com/GoFarsi/openai/utils"
69+
"log"
70+
)
71+
72+
var code string = `
73+
func add(a, b int) int {
74+
return a + b
75+
}
76+
`
77+
78+
func main() {
79+
cli, err := client.New(os.Getenv("OPENAI_API_KEY"))
80+
if err != nil {
81+
log.Fatalln(err)
82+
}
83+
84+
c := openai.NewCompletion(cli)
85+
resp, err := c.CreateCompletionFromPattern(context.Background(), openai.ProgrammingLanguageTranslator(
86+
code,
87+
utils.Go,
88+
utils.Python,
89+
))
90+
91+
if err != nil {
92+
log.Fatalln(err)
93+
}
94+
95+
log.Println(resp.Choices[0].Text)
96+
}
97+
98+
```
99+
58100
See more details in [documentation](https://pkg.go.dev/github.com/GoFarsi/openai).
59101

60102
## TODO

0 commit comments

Comments
 (0)