mirror of
https://github.com/kardolus/chatgpt-cli.git
synced 2024-09-08 23:15:00 +03:00
Add configurable auth header and token prefix
This commit is contained in:
@@ -182,6 +182,8 @@ Configuration variables:
|
||||
| `url` | The base URL for the OpenAI API. | 'https://api.openai.com' |
|
||||
| `completions_path` | The API endpoint for completions. | '/v1/chat/completions' |
|
||||
| `models_path` | The API endpoint for accessing model information. | '/v1/models' |
|
||||
| `auth_header` | The header used for authorization in API requests. | 'Authorization' |
|
||||
| `auth_token_prefix` | The prefix to be added before the token in the `auth_header`. | 'Bearer ' |
|
||||
|
||||
The defaults can be overridden by providing your own values in the user configuration file,
|
||||
named `.chatgpt-cli/config.yaml`, located in your home directory.
|
||||
|
||||
@@ -15,6 +15,8 @@ const (
|
||||
openAIURL = "https://api.openai.com"
|
||||
openAICompletionsPath = "/v1/chat/completions"
|
||||
openAIModelsPath = "/v1/models"
|
||||
openAIAuthHeader = "Authorization"
|
||||
openAIAuthTokenPrefix = "Bearer "
|
||||
openAIRole = "You are a helpful assistant."
|
||||
openAIThread = "default"
|
||||
openAITemperature = 1.0
|
||||
@@ -61,6 +63,8 @@ func (f *FileIO) ReadDefaults() types.Config {
|
||||
URL: openAIURL,
|
||||
CompletionsPath: openAICompletionsPath,
|
||||
ModelsPath: openAIModelsPath,
|
||||
AuthHeader: openAIAuthHeader,
|
||||
AuthTokenPrefix: openAIAuthTokenPrefix,
|
||||
Thread: openAIThread,
|
||||
Temperature: openAITemperature,
|
||||
TopP: openAITopP,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,14 +13,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
bearer = "Bearer %s"
|
||||
contentType = "application/json"
|
||||
errFailedToRead = "failed to read response: %w"
|
||||
errFailedToCreateRequest = "failed to create request: %w"
|
||||
errFailedToMakeRequest = "failed to make request: %w"
|
||||
errHTTP = "http status %d: %s"
|
||||
errHTTPStatus = "http status: %d"
|
||||
headerAuthorization = "Authorization"
|
||||
headerContentType = "Content-Type"
|
||||
)
|
||||
|
||||
@@ -139,7 +137,7 @@ func (r *RestCaller) newRequest(method, url string, body []byte) (*http.Request,
|
||||
}
|
||||
|
||||
if r.config.APIKey != "" {
|
||||
req.Header.Set(headerAuthorization, fmt.Sprintf(bearer, r.config.APIKey))
|
||||
req.Header.Set(r.config.AuthHeader, r.config.AuthTokenPrefix+r.config.APIKey)
|
||||
}
|
||||
req.Header.Set(headerContentType, contentType)
|
||||
|
||||
|
||||
@@ -15,4 +15,6 @@ type Config struct {
|
||||
URL string `yaml:"url"`
|
||||
CompletionsPath string `yaml:"completions_path"`
|
||||
ModelsPath string `yaml:"models_path"`
|
||||
AuthHeader string `yaml:"auth_header"`
|
||||
AuthTokenPrefix string `yaml:"auth_token_prefix"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user