Skip to content

Commit

Permalink
add original flag to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
reminia committed Nov 29, 2023
1 parent f4ad5eb commit 9fdb9f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ A simple translate api that proxies to openai written by Golang.

2. Build by `make build`.
3. Start server by `./translate`. Try it with:
```bash
curl -X POST \
-d '{"content": "Hi, how are you?", "lang": "Chinese", "model": "gpt-3.5-turbo"}' \
http://localhost:8080/translate
```
4. translate-cli is a way to test translate endpoint, start translate server before using the cli tool.

```bash
curl -X POST \
-d '{"content": "Hi, how are you?", "lang": "Chinese", "model": "gpt-3.5-turbo"}' \
http://localhost:8080/translate
```

4. translate-cli is a way to test translate endpoints, start translate server before using the cli tool.
Try it like `./translate-cli -c "content" -l "Chinese" -m "gpt-3.5-turbo"`, -l and -m are optional.
The endpoint is http://localhost:8080 by default, customize it by setting TRANSLATE_ENDPOINT env var.

Expand Down
7 changes: 7 additions & 0 deletions translate-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var endpoint = String(os.Getenv("TRANSLATE_ENDPOINT")).
orElse("http://localhost:8080/translate").
get()

var original = false

func parseFlags() Ask {
var (
content string
Expand All @@ -22,6 +24,7 @@ func parseFlags() Ask {
flag.StringVar(&content, "c", "", "The content to be translated")
flag.StringVar(&lang, "l", "English", "The language to be translated")
flag.StringVar(&model, "m", "gpt-3.5-turbo", "The chatGPT model to be chose")
flag.BoolVar(&original, "o", false, "Set to get original OpenAI response")
flag.Parse()

payload := Ask{
Expand All @@ -34,6 +37,10 @@ func parseFlags() Ask {

func translate(ask Ask) Answer {
_bytes, _ := json.Marshal(ask)
fmt.Println("original", original)
if original {
endpoint = "http://localhost:8080/translate/openai"
}
resp, _ := http.Post(endpoint, "application/json", bytes.NewBuffer(_bytes))
defer resp.Body.Close()

Expand Down

0 comments on commit 9fdb9f7

Please sign in to comment.