Skip to content

Commit 698af49

Browse files
committed
add --env argument to simplify debugging
improve readme about model env variable
1 parent ab4d90e commit 698af49

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ You need to connect your OpenAI API key to the program by setting the `OPENAI_AP
7070
export OPENAI_API_KEY=<your_api_key>
7171
```
7272

73-
By default we use `text-davinci-002`, you can change it to a different model by setting the `HOWTO_OPENAI_MODEL` environment variable. It's best to use Codex models (e.g., `code-davinci-002`), but they are currently in beta and not available to everyone.
73+
By default we use `text-davinci-002`, you can change it to a different model by setting the `HOWTO_OPENAI_MODEL` environment variable. It's best to use Codex models (e.g., `code-davinci-002`), but *code models are currently in beta and not available to everyone*.
7474

7575
```bash
76-
export HOWTO_OPENAI_MODEL=code-davinci-002
76+
export HOWTO_OPENAI_MODEL=<model_to_use> # optional, default is text-davinci-002
7777
```
7878

7979
# Disclaimer

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module howto
1+
module github.com/guitaricet/howto
22

33
go 1.19

main.go

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,11 @@ import (
66
"fmt"
77
"net/http"
88
"os"
9+
"runtime"
910
"strings"
1011
"time"
1112
)
1213

13-
// {
14-
// "id": "cmpl-623HpLk0do5u61ZSmfvqkefqdyc2T",
15-
// "object": "text_completion",
16-
// "created": 1665947309,
17-
// "model": "code-davinci-002",
18-
// "choices": [
19-
// {
20-
// "text": "\nmore code\n\nmore code\n\nmore code\n\nmore code\n\nmore code",
21-
// "index": 0,
22-
// "logprobs": null,
23-
// "finish_reason": "length"
24-
// }
25-
// ],
26-
// "usage": {
27-
// "prompt_tokens": 4,
28-
// "completion_tokens": 256,
29-
// "total_tokens": 260
30-
// }
31-
// }
32-
3314
type OpenAiResponse struct {
3415
Id string `json:"intValue"`
3516
Object string `json:"stringValue"`
@@ -40,12 +21,39 @@ type Choice struct {
4021
Text string `json:"text"`
4122
}
4223

24+
const VERSION = "1.0.3"
25+
26+
func printEnvInfo() {
27+
fmt.Println("Howto version: " + VERSION)
28+
fmt.Println("OS: " + runtime.GOOS)
29+
30+
httpkey := os.Getenv("OPENAI_API_KEY")
31+
if httpkey == "" {
32+
fmt.Println("OpenAI API key: not set")
33+
} else if httpkey[:3] == "sk-" {
34+
fmt.Println("OpenAI API key: set")
35+
} else {
36+
fmt.Println("OpenAI API key: invalid (does not start with sk-)")
37+
}
38+
39+
modelName := os.Getenv("HOWTO_OPENAI_MODEL")
40+
if modelName == "" {
41+
fmt.Println("OpenAI model: not set")
42+
} else {
43+
fmt.Println("OpenAI model: " + modelName)
44+
}
45+
}
46+
4347
func main() {
4448
if len(os.Args) < 2 || os.Args[1] == "--help" {
4549
fmt.Println("Usage: howto <prompt>")
4650
fmt.Println("To use howto, pass it a prompt to complete. For example: `howto tar file without compression`")
4751
return
4852
}
53+
if len(os.Args) < 2 || os.Args[1] == "--env" {
54+
printEnvInfo()
55+
return
56+
}
4957

5058
httpkey := os.Getenv("OPENAI_API_KEY")
5159
if httpkey == "" {
@@ -114,6 +122,6 @@ func main() {
114122
command = command[:index]
115123
}
116124
command = strings.Trim(command, "\n")
117-
125+
118126
fmt.Println(command)
119127
}

0 commit comments

Comments
 (0)