-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * fix: remove package * #3: project organization * #3-feat: build chat api * #3 rename func * Remove unused dependencies from go.sum * #3: Add .env to .gitignore --------- Co-authored-by: Max <mkrueger190@gmail.com>
- Loading branch information
1 parent
1154fe8
commit 72e75e8
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
dist | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module glide | ||
|
||
go 1.21.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package openai | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
type ProviderAPIConfig struct { | ||
BaseURL string | ||
Headers func(string) http.Header | ||
Complete string | ||
Chat string | ||
Embed string | ||
} | ||
|
||
func OpenAIAPIConfig(APIKey string) *ProviderAPIConfig { | ||
return &ProviderAPIConfig{ | ||
BaseURL: "https://api.openai.com/v1", | ||
Headers: func(APIKey string) http.Header { | ||
headers := make(http.Header) | ||
headers.Set("Authorization", fmt.Sprintf("Bearer %s", APIKey)) | ||
return headers | ||
}, | ||
Complete: "/completions", | ||
Chat: "/chat/completions", | ||
Embed: "/embeddings", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package openai | ||
|
||
type ProviderConfig struct { | ||
Model ConfigItem `json:"model"` | ||
Messages ConfigItem `json:"messages"` | ||
Functions ConfigItem `json:"functions"` | ||
FunctionCall ConfigItem `json:"function_call"` | ||
MaxTokens NumericConfigItem `json:"max_tokens"` | ||
Temperature NumericConfigItem `json:"temperature"` | ||
TopP NumericConfigItem `json:"top_p"` | ||
N NumericConfigItem `json:"n"` | ||
Stream BoolConfigItem `json:"stream"` | ||
Stop ConfigItem `json:"stop"` | ||
PresencePenalty NumericConfigItem `json:"presence_penalty"` | ||
FrequencyPenalty NumericConfigItem `json:"frequency_penalty"` | ||
LogitBias ConfigItem `json:"logit_bias"` | ||
User ConfigItem `json:"user"` | ||
Seed ConfigItem `json:"seed"` | ||
Tools ConfigItem `json:"tools"` | ||
ToolChoice ConfigItem `json:"tool_choice"` | ||
ResponseFormat ConfigItem `json:"response_format"` | ||
} | ||
|
||
type ConfigItem struct { | ||
Param string `json:"param"` | ||
Required bool `json:"required,omitempty"` | ||
Default interface{} `json:"default,omitempty"` | ||
Min interface{} `json:"min,omitempty"` | ||
Max interface{} `json:"max,omitempty"` | ||
} | ||
|
||
type NumericConfigItem struct { | ||
Param string `json:"param"` | ||
Default float64 `json:"default,omitempty"` | ||
Min float64 `json:"min,omitempty"` | ||
Max float64 `json:"max,omitempty"` | ||
} | ||
|
||
type BoolConfigItem struct { | ||
Param string `json:"param"` | ||
Default bool `json:"default,omitempty"` | ||
} | ||
|
||
// DefaultProviderConfig returns an instance of ProviderConfig with default values. | ||
func OpenAiDefaultConfig() ProviderConfig { | ||
return ProviderConfig{ | ||
Model: ConfigItem{ | ||
Param: "model", | ||
Required: true, | ||
Default: "gpt-3.5-turbo", | ||
}, | ||
Messages: ConfigItem{ | ||
Param: "messages", | ||
Default: "", | ||
}, | ||
Functions: ConfigItem{ | ||
Param: "functions", | ||
}, | ||
FunctionCall: ConfigItem{ | ||
Param: "function_call", | ||
}, | ||
MaxTokens: NumericConfigItem{ | ||
Param: "max_tokens", | ||
Default: 100, | ||
Min: 0, | ||
}, | ||
Temperature: NumericConfigItem{ | ||
Param: "temperature", | ||
Default: 1, | ||
Min: 0, | ||
Max: 2, | ||
}, | ||
TopP: NumericConfigItem{ | ||
Param: "top_p", | ||
Default: 1, | ||
Min: 0, | ||
Max: 1, | ||
}, | ||
N: NumericConfigItem{ | ||
Param: "n", | ||
Default: 1, | ||
}, | ||
Stream: BoolConfigItem{ | ||
Param: "stream", | ||
Default: false, | ||
}, | ||
Stop: ConfigItem{ | ||
Param: "stop", | ||
}, | ||
PresencePenalty: NumericConfigItem{ | ||
Param: "presence_penalty", | ||
Min: -2, | ||
Max: 2, | ||
}, | ||
FrequencyPenalty: NumericConfigItem{ | ||
Param: "frequency_penalty", | ||
Min: -2, | ||
Max: 2, | ||
}, | ||
LogitBias: ConfigItem{ | ||
Param: "logit_bias", | ||
}, | ||
User: ConfigItem{ | ||
Param: "user", | ||
}, | ||
Seed: ConfigItem{ | ||
Param: "seed", | ||
}, | ||
Tools: ConfigItem{ | ||
Param: "tools", | ||
}, | ||
ToolChoice: ConfigItem{ | ||
Param: "tool_choice", | ||
}, | ||
ResponseFormat: ConfigItem{ | ||
Param: "response_format", | ||
}, | ||
} | ||
} |