Skip to content

Commit

Permalink
fix: only set completion response format when api is openai (#213)
Browse files Browse the repository at this point in the history
closes #206

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 authored Feb 6, 2024
1 parent db3a762 commit f979f9e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,13 @@ func (m *Mods) startCompletionCmd(content string) tea.Cmd {
stream, err := client.CreateChatCompletionStream(
ctx,
openai.ChatCompletionRequest{
Model: mod.Name,
Temperature: noOmitFloat(cfg.Temperature),
TopP: noOmitFloat(cfg.TopP),
MaxTokens: cfg.MaxTokens,
Messages: m.messages,
Stream: true,
ResponseFormat: &openai.ChatCompletionResponseFormat{
Type: responseType(cfg),
},
Model: mod.Name,
Temperature: noOmitFloat(cfg.Temperature),
TopP: noOmitFloat(cfg.TopP),
MaxTokens: cfg.MaxTokens,
Messages: m.messages,
Stream: true,
ResponseFormat: responseFormat(cfg),
},
)
ae := &openai.APIError{}
Expand Down Expand Up @@ -623,6 +621,16 @@ func removeWhitespace(s string) string {
return s
}

func responseFormat(cfg *Config) *openai.ChatCompletionResponseFormat {
if cfg.API != "openai" {
// only openai's api supports ChatCompletionResponseFormat
return nil
}
return &openai.ChatCompletionResponseFormat{
Type: responseType(cfg),
}
}

func responseType(cfg *Config) openai.ChatCompletionResponseFormatType {
if !cfg.Format {
return openai.ChatCompletionResponseFormatTypeText
Expand Down

0 comments on commit f979f9e

Please sign in to comment.