Skip to content

Commit

Permalink
feat(model): Introduce Groq package with Model type and related funct…
Browse files Browse the repository at this point in the history
…ions (#148)

Here's a summary of the git diff:

* Changed the name of the `model.go` file to `groq/model.go`
* Added a new package called `groq`
* Added a new type called `Model` that has three string values: `LLaMA270bChat`, `Mixtral8x7bInstructV01`, and `Gemma7bIt`
* Added a function called `GetModel` that takes a `Model` value and returns a string representing the model name
* Added a function called `IsValid` that takes a `Model` value and returns a boolean indicating whether the model is valid
* Added a map called `model` that maps the three `Model` values to their corresponding string names
* Changed the `README.md` file to include information about the new `groq` package and the `Model` type

Overall, it seems like this commit adds a new package called `groq` that contains a new type called `Model` and some functions related to that type. The `README.md` file was also updated to include information about the new package and type.

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Mar 22, 2024
1 parent 0f04268 commit 296d527
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 27 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ codegpt config set openai.api_key xxxxxxxxxxxxxxxx
codegpt config set openai.model_name xxxxx-gpt-35-turbo
```

### How to change to Groq API Service

Please get the `API key` from Groq API Service, please vist [here][31]. Update the `base_url` and `api_key` in your config file.

```sh
codegpt config set openai.provider openai
codegpt config set openai.base_url https://api.groq.com/openai/v1
codegpt config set openai.api_key gsk_xxxxxxxxxxxxxx
```

Support the [following models][32]:

1. LLaMA2-70b (Meta) **recommended**
2. Mixtral-8x7b (Mistral)
3. Gemma-7b-it (Google)

[31]: https://console.groq.com/keys
[32]: https://console.groq.com/docs/models

## Usage

There are two methods for generating a commit message using the `codegpt` command. The first is CLI mode, and the second is Git Hook.
Expand Down
40 changes: 40 additions & 0 deletions groq/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package groq

type Model string

const (
LLaMA270bChat Model = "LLaMA2-70b-chat"
Mixtral8x7bInstructV01 Model = "Mixtral-8x7b-Instruct-v0.1"
Gemma7bIt Model = "Gemma-7b-it"
)

func (m Model) String() string {
return string(m)
}

func (m Model) GetModel() string {
return GetModel(m)
}

func (m Model) IsVaild() bool {
switch m {
case LLaMA270bChat, Mixtral8x7bInstructV01, Gemma7bIt:
return true
default:
return false
}
}

var model = map[Model]string{
LLaMA270bChat: "llama2-70b-4096",
Mixtral8x7bInstructV01: "mixtral-8x7b-32768",
Gemma7bIt: "gemma-7b-it",
}

// GetModel returns the model name.
func GetModel(modelName Model) string {
if _, ok := model[modelName]; !ok {
return model[LLaMA270bChat]
}
return model[modelName]
}
70 changes: 43 additions & 27 deletions openai/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"net/url"

"github.com/appleboy/CodeGPT/groq"

openai "github.com/sashabaranov/go-openai"
"golang.org/x/net/proxy"
)
Expand All @@ -16,32 +18,35 @@ var DefaultModel = openai.GPT3Dot5Turbo

// modelMaps maps model names to their corresponding model ID strings.
var modelMaps = map[string]string{
"gpt-4-32k-0613": openai.GPT432K0613,
"gpt-4-32k-0314": openai.GPT432K0314,
"gpt-4-32k": openai.GPT432K,
"gpt-4-0613": openai.GPT40613,
"gpt-4-0314": openai.GPT40314,
"gpt-4-0125-preview": openai.GPT4Turbo0125,
"gpt-4-1106-preview": openai.GPT4Turbo1106,
"gpt-4-turbo-preview": openai.GPT4TurboPreview,
"gpt-4-vision-preview": openai.GPT4VisionPreview,
"gpt-4": openai.GPT4,
"gpt-3.5-turbo-0125": openai.GPT3Dot5Turbo0125,
"gpt-3.5-turbo-1106": openai.GPT3Dot5Turbo1106,
"gpt-3.5-turbo-0613": openai.GPT3Dot5Turbo0613,
"gpt-3.5-turbo-0301": openai.GPT3Dot5Turbo0301,
"gpt-3.5-turbo-16k": openai.GPT3Dot5Turbo16K,
"gpt-3.5-turbo-16k-0613": openai.GPT3Dot5Turbo16K0613,
"gpt-3.5-turbo": openai.GPT3Dot5Turbo,
"gpt-3.5-turbo-instruct": openai.GPT3Dot5TurboInstruct,
"davinci": openai.GPT3Davinci,
"davinci-002": openai.GPT3Davinci002,
"curie": openai.GPT3Curie,
"curie-002": openai.GPT3Curie002,
"ada": openai.GPT3Ada,
"ada-002": openai.GPT3Ada002,
"babbage": openai.GPT3Babbage,
"babbage-002": openai.GPT3Babbage002,
"gpt-4-32k-0613": openai.GPT432K0613,
"gpt-4-32k-0314": openai.GPT432K0314,
"gpt-4-32k": openai.GPT432K,
"gpt-4-0613": openai.GPT40613,
"gpt-4-0314": openai.GPT40314,
"gpt-4-0125-preview": openai.GPT4Turbo0125,
"gpt-4-1106-preview": openai.GPT4Turbo1106,
"gpt-4-turbo-preview": openai.GPT4TurboPreview,
"gpt-4-vision-preview": openai.GPT4VisionPreview,
"gpt-4": openai.GPT4,
"gpt-3.5-turbo-0125": openai.GPT3Dot5Turbo0125,
"gpt-3.5-turbo-1106": openai.GPT3Dot5Turbo1106,
"gpt-3.5-turbo-0613": openai.GPT3Dot5Turbo0613,
"gpt-3.5-turbo-0301": openai.GPT3Dot5Turbo0301,
"gpt-3.5-turbo-16k": openai.GPT3Dot5Turbo16K,
"gpt-3.5-turbo-16k-0613": openai.GPT3Dot5Turbo16K0613,
"gpt-3.5-turbo": openai.GPT3Dot5Turbo,
"gpt-3.5-turbo-instruct": openai.GPT3Dot5TurboInstruct,
"davinci": openai.GPT3Davinci,
"davinci-002": openai.GPT3Davinci002,
"curie": openai.GPT3Curie,
"curie-002": openai.GPT3Curie002,
"ada": openai.GPT3Ada,
"ada-002": openai.GPT3Ada002,
"babbage": openai.GPT3Babbage,
"babbage-002": openai.GPT3Babbage002,
groq.LLaMA270bChat.String(): groq.LLaMA270bChat.GetModel(),
groq.Mixtral8x7bInstructV01.String(): groq.Mixtral8x7bInstructV01.GetModel(),
groq.Gemma7bIt.String(): groq.Gemma7bIt.GetModel(),
}

// GetModel returns the model ID corresponding to the given model name.
Expand Down Expand Up @@ -95,6 +100,10 @@ func (c *Client) CreateFunctionCall(
FrequencyPenalty: c.frequencyPenalty,
PresencePenalty: c.presencePenalty,
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: "You are a helpful assistant.",
},
{
Role: openai.ChatMessageRoleUser,
Content: content,
Expand All @@ -119,6 +128,10 @@ func (c *Client) CreateChatCompletion(
FrequencyPenalty: c.frequencyPenalty,
PresencePenalty: c.presencePenalty,
Messages: []openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleSystem,
Content: "You are a helpful assistant.",
},
{
Role: openai.ChatMessageRoleUser,
Content: content,
Expand Down Expand Up @@ -176,7 +189,10 @@ func (c *Client) Completion(
openai.GPT4Turbo1106,
openai.GPT4Turbo0125,
openai.GPT4TurboPreview,
openai.GPT4VisionPreview:
openai.GPT4VisionPreview,
groq.LLaMA270bChat.GetModel(),
groq.Mixtral8x7bInstructV01.GetModel(),
groq.Gemma7bIt.GetModel():
r, err := c.CreateChatCompletion(ctx, content)
if err != nil {
return nil, err
Expand Down

0 comments on commit 296d527

Please sign in to comment.