Skip to content

Commit

Permalink
#29: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger12 committed Dec 20, 2023
1 parent f38473e commit cc13f38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
30 changes: 13 additions & 17 deletions pkg/providers/openai/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"io"
"log/slog"
"net/http"
"strings"
"reflect"
"strings"
)

const (
Expand All @@ -24,16 +24,16 @@ type ChatRequest struct {
TopP float64 `json:"top_p" validate:"omitempty,gte=0,lte=1"`
MaxTokens int `json:"max_tokens" validate:"omitempty,gte=0"`
N int `json:"n" validate:"omitempty,gte=1"`
StopWords []string `json:"stop,omitempty"`
Stream bool `json:"stream,omitempty" validate:"omitempty, boolean"`
FrequencyPenalty int `json:"frequency_penalty,omitempty"`
PresencePenalty int `json:"presence_penalty,omitempty"`
LogitBias *map[int]float64 `json:"logit_bias,omitempty" validate:"omitempty"`
User interface{} `json:"user,omitempty"`
Seed interface{} `json:"seed,omitempty" validate:"omitempty,gte=0"`
Tools []string `json:"tools,omitempty"`
ToolChoice interface{} `json:"tool_choice,omitempty"`
ResponseFormat interface{} `json:"response_format,omitempty"`
StopWords []string `json:"stop"`
Stream bool `json:"stream" validate:"omitempty, boolean"`
FrequencyPenalty int `json:"frequency_penalty"`
PresencePenalty int `json:"presence_penalty"`
LogitBias *map[int]float64 `json:"logit_bias" validate:"omitempty"`
User interface{} `json:"user"`
Seed interface{} `json:"seed" validate:"omitempty,gte=0"`
Tools []string `json:"tools"`
ToolChoice interface{} `json:"tool_choice"`
ResponseFormat interface{} `json:"response_format"`

// StreamingFunc is a function to be called for each chunk of a streaming response.
// Return an error to stop streaming early.
Expand Down Expand Up @@ -115,15 +115,12 @@ func (c *Client) CreateChatRequest(message []byte) *ChatRequest {

for i := 0; i < chatRequestValue.NumField(); i++ {
jsonTag := chatRequestType.Field(i).Tag.Get("json")
fmt.Println(jsonTag)
if value, ok := defaultParams[jsonTag]; ok {
fieldValue := chatRequestValue.Field(i)
fieldValue.Set(reflect.ValueOf(value))
}
}

fmt.Println(chatRequest, defaultParams)

return chatRequest
}

Expand Down Expand Up @@ -159,7 +156,6 @@ type StreamedChatResponsePayload struct {

// CreateChatResponse creates chat Response.
func (c *Client) CreateChatResponse(ctx context.Context, r *ChatRequest) (*ChatResponse, error) {

_ = ctx // keep this for future use

resp, err := c.createChatHTTP(r)
Expand Down Expand Up @@ -307,7 +303,7 @@ func (c *Client) buildAzureURL(suffix string, model string) string {
func (c *Client) setModel() string {
if c.Provider.Model == "" {
return defaultChatModel
} else {
return c.Provider.Model
}

return c.Provider.Model
}
6 changes: 2 additions & 4 deletions pkg/providers/openai/openaiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
// Client is a client for the OpenAI API.
type Client struct {
Provider providers.Provider
PoolName string
PoolName string
baseURL string
payload []byte
organization string
Expand All @@ -67,7 +67,6 @@ type Client struct {
// - *Client: A pointer to the created client.
// - error: An error if the client creation failed.
func OpenAiClient(poolName string, modelName string, payload []byte) (*Client, error) {

Check warning on line 69 in pkg/providers/openai/openaiclient.go

View workflow job for this annotation

GitHub Actions / Static Checks

exported: func name will be used as openai.OpenAiClient by other packages, and that stutters; consider calling this Client (revive)

providerName := "openai"

// Read the YAML file
Expand Down Expand Up @@ -138,11 +137,10 @@ func OpenAiClient(poolName string, modelName string, payload []byte) (*Client, e
//
// Parameters:
// - payload: The user payload for the chat request.
// Returns:
// Returns:
// - *ChatResponse: a pointer to a ChatResponse
// - error: An error if the request failed.
func (c *Client) Chat() (*ChatResponse, error) {

// Create a new chat request

slog.Info("creating chat request")
Expand Down

0 comments on commit cc13f38

Please sign in to comment.