Skip to content

Commit

Permalink
Merge pull request #4 from josh-wong/update-readme
Browse files Browse the repository at this point in the history
Revise repository README
  • Loading branch information
josh-wong authored Aug 3, 2024
2 parents ac5dbc2 + d91a47a commit df291cd
Showing 1 changed file with 58 additions and 54 deletions.
112 changes: 58 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,83 @@ Go-ChatGPT is an open-source GoLang client for ChatGPT, a large language model t

## Features

- [x] Easy-to-use GoLang client for ChatGPT
- [x] Sends text to ChatGPT and receives a response
- [x] Support custom model and parameters
- [x] Supports GPT3.5 and GPT4 models

- Provides a GoLang client for ChatGPT.
- Sends text to ChatGPT and receives a response.
- Supports GPT3.5 and GPT4 models.

## Installation

You can install ChatGPT-Go using Go modules:
You can install ChatGPT-Go by using Go modules:

```bash
go get github.com/josh-wong/go-chatgpt
```

## Getting Started
Get your API key from the OpenAI Dashboard - [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys) and export this either as an environment variable, or put this your `.bashrc` or `.zshrc`
```bash
export OPENAI_KEY=sk...
## Getting started

Get your [API key from the OpenAI Dashboard](https://platform.openai.com/account/api-keys) and export this either as an environment variable or put the API key in your `.bashrc` or `.zshrc` file, replacing `<YOUR_OPENAI_API_KEY>` with your API key:

```console
export OPENAI_KEY=<YOUR_OPENAI_API_KEY>
```

___

1. In your Go code, import the ChatGPT-Go package:
```go
import (
"github.com/josh-wong/go-chatgpt"
)
```
1. In your Go code, import the ChatGPT-Go package.

```go
import (
"github.com/josh-wong/go-chatgpt"
)
```

2. Create a new ChatGPT client with your API key
```go
2. Create a new ChatGPT client that uses your API key.

```go
key := os.Getenv("OPENAI_KEY")
client, err := chatgpt.NewClient(key)
if err != nil {
log.Fatal(err)
}
```
if err != nil {
log.Fatal(err)
}
```

3. Use the `SimpleSend` API to send text to ChatGPT and get a response.
```go
ctx := context.Background()
res, err := c.SimpleSend(ctx, "Hello, how are you?")
if err != nil {
// handle error
}
```
The SimpleSend method sends the specified text to ChatGPT and returns a response. If an error occurs, it returns an error message.
4. To use a custom model/parameters, use the `Send` API.
```go
ctx := context.Background()
res, err = c.Send(ctx, &chatgpt.ChatCompletionRequest{
Model: chatgpt.GPT35Turbo,
Messages: []chatgpt.ChatMessage{
{
Role: chatgpt.ChatGPTModelRoleSystem,
Content: "Hey, Explain GoLang to me in 2 sentences.",
},
},
})
if err != nil {
// handle error
}
```

```go
ctx := context.Background()
res, err := c.SimpleSend(ctx, "Hello, how are you?")
if err != nil {
// Handle errors.
}
```

The SimpleSend method will send the specified text to ChatGPT and return a response. If an error occurs, an error message will be returned.

4. To use a model and/or parameters, use the `Send` API. For example, the following uses the gpt-3.5-turbo (`GPT35Turbo`) model.

```go
ctx := context.Background()
res, err = c.Send(ctx, &chatgpt.ChatCompletionRequest{
Model: chatgpt.GPT35Turbo,
Messages: []chatgpt.ChatMessage{
{
Role: chatgpt.ChatGPTModelRoleSystem,
Content: "Hey, explain GoLang to me in two sentences.",
},
},
})
if err != nil {
// Handle errors.
}
```

## Contribute
If you want to contribute to this project, feel free to open a PR or an issue.

If you want to contribute to this project, feel free to open a PR or an issue.

## License
This package is licensed under MIT license. See [LICENSE](./LICENSE) for details.


___
[![codecov](https://codecov.io/gh/josh-wong/go-chatgpt/branch/main/graph/badge.svg?token=2VXFP3238M)](https://codecov.io/gh/josh-wong/go-chatgpt)
[![Go](https://github.com/josh-wong/go-chatgpt/actions/workflows/go.yml/badge.svg)](https://github.com/josh-wong/go-chatgpt/actions/workflows/go.yml)
This package is licensed under the MIT license. See [LICENSE](./LICENSE) for details.

0 comments on commit df291cd

Please sign in to comment.