Skip to content

Commit

Permalink
#29: gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger12 committed Dec 20, 2023
1 parent c9d9402 commit 2f3695a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ bin
glide
tmp
coverage.txt
precommit.txt
34 changes: 16 additions & 18 deletions pkg/providers/openai/openai_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
package openai

import (
"testing"
"encoding/json"
"fmt"
"testing"
)



func TestOpenAIClient(t *testing.T) {

Check warning on line 9 in pkg/providers/openai/openai_test.go

View workflow job for this annotation

GitHub Actions / Static Checks

unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
// Initialize the OpenAI client

poolName := "default"
modelName := "gpt-3.5-turbo"

payload := map[string]interface{}{
"message": []map[string]string{
{
"role": "system",
"content": "You are a helpful assistant.",
},
{
"role": "user",
"content": "tell me a joke",
},
},
"messageHistory": []string{"Hello there", "How are you?", "I'm good, how about you?"},
}

payloadBytes, _ := json.Marshal(payload)
"message": []map[string]string{
{
"role": "system",
"content": "You are a helpful assistant.",
},
{
"role": "user",
"content": "tell me a joke",
},
},
"messageHistory": []string{"Hello there", "How are you?", "I'm good, how about you?"},
}

payloadBytes, _ := json.Marshal(payload)

c := &Client{}

Expand All @@ -37,4 +35,4 @@ func TestOpenAIClient(t *testing.T) {
respJSON, _ := json.Marshal(resp)

fmt.Println(string(respJSON))
}
}
9 changes: 4 additions & 5 deletions pkg/providers/openai/openaiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
)

const (
defaultBaseURL = "https://api.openai.com/v1"
defaultOrganization = ""
defaultBaseURL = "https://api.openai.com/v1"
defaultOrganization = ""
)

// ErrEmptyResponse is returned when the OpenAI API returns an empty response.
Expand All @@ -41,6 +41,7 @@ const (
APITypeAzure APIType = "AZURE"
APITypeAzureAD APIType = "AZURE_AD"
)

// Client is a client for the OpenAI API.
type Client struct {
Provider providers.Provider
Expand All @@ -53,7 +54,6 @@ type Client struct {
apiVersion string
}


func (c *Client) Run(poolName string, modelName string, payload []byte) (*ChatResponse, error) {

c, err := c.NewClient(poolName, modelName)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *Client) NewClient(poolName string, modelName string) (*Client, error) {

// Read the YAML file
data, err := os.ReadFile("/Users/max/code/Glide/config.yaml")

if err != nil {
slog.Error("Failed to read file: %v", err)
return nil, err
Expand Down Expand Up @@ -156,4 +156,3 @@ func HttpClient() *client.Client {
return c

}

20 changes: 10 additions & 10 deletions pkg/providers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ type PoolsConfig struct {
}

type Pool struct {
Name string `yaml:"pool"`
Balancing string `yaml:"balancing"`
Providers []Provider `yaml:"providers"`
Name string `yaml:"pool"`
Balancing string `yaml:"balancing"`
Providers []Provider `yaml:"providers"`
}

type Provider struct {
Provider string `yaml:"provider"`
Model string `yaml:"model"`
ApiKey string `yaml:"api_key"`
TimeoutMs int `yaml:"timeout_ms,omitempty"`
DefaultParams map[string]interface{} `yaml:"default_params,omitempty"`
Provider string `yaml:"provider"`
Model string `yaml:"model"`
ApiKey string `yaml:"api_key"`

Check warning on line 19 in pkg/providers/types.go

View workflow job for this annotation

GitHub Actions / Static Checks

var-naming: struct field ApiKey should be APIKey (revive)
TimeoutMs int `yaml:"timeout_ms,omitempty"`
DefaultParams map[string]interface{} `yaml:"default_params,omitempty"`
}

type RequestBody struct {
Message []struct {
Message []struct {
Role string `json:"role"`
Content string `json:"content"`
} `json:"message"`
MessageHistory []string `json:"messageHistory"`
}
}

0 comments on commit 2f3695a

Please sign in to comment.