added openaibaseurl parameter to client:set (#141)

This commit is contained in:
Cole Lashley 2023-12-13 14:03:22 -08:00 committed by GitHub
parent 96980b2f83
commit 535fd0d7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 4 deletions

View File

@ -3628,8 +3628,21 @@ func ClientSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss
return nil, fmt.Errorf("error updating client openai maxchoices: %v", err)
}
}
if aiBaseURL, found := pk.Kwargs["openaibaseurl"]; found {
aiOpts := clientData.OpenAIOpts
if aiOpts == nil {
aiOpts = &sstore.OpenAIOptsType{}
clientData.OpenAIOpts = aiOpts
}
aiOpts.BaseURL = aiBaseURL
varsUpdated = append(varsUpdated, "openaibaseurl")
err = sstore.UpdateClientOpenAIOpts(ctx, *aiOpts)
if err != nil {
return nil, fmt.Errorf("error updating client openai base url: %v", err)
}
}
if len(varsUpdated) == 0 {
return nil, fmt.Errorf("/client:set requires a value to set: %s", formatStrs([]string{"termfontsize", "openaiapitoken", "openaimodel", "openaimaxtokens", "openaimaxchoices"}, "or", false))
return nil, fmt.Errorf("/client:set requires a value to set: %s", formatStrs([]string{"termfontsize", "openaiapitoken", "openaimodel", "openaibaseurl", "openaimaxtokens", "openaimaxchoices"}, "or", false))
}
clientData, err = sstore.EnsureClientData(ctx)
if err != nil {

View File

@ -49,7 +49,11 @@ func RunCompletion(ctx context.Context, opts *sstore.OpenAIOptsType, prompt []ss
if opts.APIToken == "" {
return nil, fmt.Errorf("no api token")
}
client := openaiapi.NewClient(opts.APIToken)
clientConfig := openaiapi.DefaultConfig(opts.APIToken)
if opts.BaseURL != "" {
clientConfig.BaseURL = opts.BaseURL
}
client := openaiapi.NewClientWithConfig(clientConfig)
req := openaiapi.ChatCompletionRequest{
Model: opts.Model,
Messages: convertPrompt(prompt),
@ -78,7 +82,11 @@ func RunCompletionStream(ctx context.Context, opts *sstore.OpenAIOptsType, promp
if opts.APIToken == "" {
return nil, fmt.Errorf("no api token")
}
client := openaiapi.NewClient(opts.APIToken)
clientConfig := openaiapi.DefaultConfig(opts.APIToken)
if opts.BaseURL != "" {
clientConfig.BaseURL = opts.BaseURL
}
client := openaiapi.NewClientWithConfig(clientConfig)
req := openaiapi.ChatCompletionRequest{
Model: opts.Model,
Messages: convertPrompt(prompt),

View File

@ -433,7 +433,7 @@ func (h *HistoryItemType) FromMap(m map[string]interface{}) bool {
type ScreenOptsType struct {
TabColor string `json:"tabcolor,omitempty"`
TabIcon string `json:"tabicon,omitempty"`
TabIcon string `json:"tabicon,omitempty"`
PTerm string `json:"pterm,omitempty"`
}
@ -924,6 +924,7 @@ type RemoteOptsType struct {
type OpenAIOptsType struct {
Model string `json:"model"`
APIToken string `json:"apitoken"`
BaseURL string `json:"baseurl,omitempty"`
MaxTokens int `json:"maxtokens,omitempty"`
MaxChoices int `json:"maxchoices,omitempty"`
}