Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for o1 models in openai and azure #368

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 48 additions & 47 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,53 +130,54 @@ func (ft *FormatText) UnmarshalYAML(unmarshal func(interface{}) error) error {

// Config holds the main configuration and is mapped to the YAML settings file.
type Config struct {
Model string `yaml:"default-model" env:"MODEL"`
Format bool `yaml:"format" env:"FORMAT"`
FormatText FormatText `yaml:"format-text"`
FormatAs string `yaml:"format-as" env:"FORMAT_AS"`
Raw bool `yaml:"raw" env:"RAW"`
Quiet bool `yaml:"quiet" env:"QUIET"`
MaxTokens int `yaml:"max-tokens" env:"MAX_TOKENS"`
MaxInputChars int `yaml:"max-input-chars" env:"MAX_INPUT_CHARS"`
Temperature float32 `yaml:"temp" env:"TEMP"`
Stop []string `yaml:"stop" env:"STOP"`
TopP float32 `yaml:"topp" env:"TOPP"`
TopK int `yaml:"topk" env:"TOPK"`
NoLimit bool `yaml:"no-limit" env:"NO_LIMIT"`
CachePath string `yaml:"cache-path" env:"CACHE_PATH"`
NoCache bool `yaml:"no-cache" env:"NO_CACHE"`
IncludePromptArgs bool `yaml:"include-prompt-args" env:"INCLUDE_PROMPT_ARGS"`
IncludePrompt int `yaml:"include-prompt" env:"INCLUDE_PROMPT"`
MaxRetries int `yaml:"max-retries" env:"MAX_RETRIES"`
WordWrap int `yaml:"word-wrap" env:"WORD_WRAP"`
Fanciness uint `yaml:"fanciness" env:"FANCINESS"`
StatusText string `yaml:"status-text" env:"STATUS_TEXT"`
HTTPProxy string `yaml:"http-proxy" env:"HTTP_PROXY"`
APIs APIs `yaml:"apis"`
System string `yaml:"system"`
Role string `yaml:"role" env:"ROLE"`
AskModel bool
API string
Models map[string]Model
Roles map[string][]string
ShowHelp bool
ResetSettings bool
Prefix string
Version bool
Settings bool
Dirs bool
Theme string
SettingsPath string
ContinueLast bool
Continue string
Title string
ShowLast bool
Show string
List bool
ListRoles bool
Delete string
DeleteOlderThan time.Duration
User string
Model string `yaml:"default-model" env:"MODEL"`
Format bool `yaml:"format" env:"FORMAT"`
FormatText FormatText `yaml:"format-text"`
FormatAs string `yaml:"format-as" env:"FORMAT_AS"`
Raw bool `yaml:"raw" env:"RAW"`
Quiet bool `yaml:"quiet" env:"QUIET"`
MaxTokens int `yaml:"max-tokens" env:"MAX_TOKENS"`
MaxCompletionTokens int `yaml:"max-completion-tokens" env:"MAX_COMPLETION_TOKENS"`
MaxInputChars int `yaml:"max-input-chars" env:"MAX_INPUT_CHARS"`
Temperature float32 `yaml:"temp" env:"TEMP"`
Stop []string `yaml:"stop" env:"STOP"`
TopP float32 `yaml:"topp" env:"TOPP"`
TopK int `yaml:"topk" env:"TOPK"`
NoLimit bool `yaml:"no-limit" env:"NO_LIMIT"`
CachePath string `yaml:"cache-path" env:"CACHE_PATH"`
NoCache bool `yaml:"no-cache" env:"NO_CACHE"`
IncludePromptArgs bool `yaml:"include-prompt-args" env:"INCLUDE_PROMPT_ARGS"`
IncludePrompt int `yaml:"include-prompt" env:"INCLUDE_PROMPT"`
MaxRetries int `yaml:"max-retries" env:"MAX_RETRIES"`
WordWrap int `yaml:"word-wrap" env:"WORD_WRAP"`
Fanciness uint `yaml:"fanciness" env:"FANCINESS"`
StatusText string `yaml:"status-text" env:"STATUS_TEXT"`
HTTPProxy string `yaml:"http-proxy" env:"HTTP_PROXY"`
APIs APIs `yaml:"apis"`
System string `yaml:"system"`
Role string `yaml:"role" env:"ROLE"`
AskModel bool
API string
Models map[string]Model
Roles map[string][]string
ShowHelp bool
ResetSettings bool
Prefix string
Version bool
Settings bool
Dirs bool
Theme string
SettingsPath string
ContinueLast bool
Continue string
Title string
ShowLast bool
Show string
List bool
ListRoles bool
Delete string
DeleteOlderThan time.Duration
User string

cacheReadFromID, cacheWriteToID, cacheWriteToTitle string
}
Expand Down
14 changes: 14 additions & 0 deletions config_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ theme: charm
max-input-chars: 12250
# {{ index .Help "max-tokens" }}
# max-tokens: 100
# {{ index .Help "max-completion-tokens" }}
max-completion-tokens: 100
# {{ index .Help "apis" }}
apis:
openai:
Expand Down Expand Up @@ -90,6 +92,12 @@ apis:
aliases: ["35"]
max-input-chars: 12250
fallback:
o1-preview:
aliases: ["o1-preview"]
max-input-chars: 128000
o1-mini:
aliases: ["o1-mini"]
max-input-chars: 128000
anthropic:
base-url: https://api.anthropic.com/v1
api-key:
Expand Down Expand Up @@ -242,6 +250,12 @@ apis:
aliases: ["az35"]
max-input-chars: 12250
fallback:
o1-preview:
aliases: ["o1-preview"]
max-input-chars: 128000
o1-mini:
aliases: ["o1-mini"]
max-input-chars: 128000
runpod:
# https://docs.runpod.io/serverless/workers/vllm/openai-compatibility
base-url: https://api.runpod.ai/v2/${YOUR_ENDPOINT}/openai/v1
Expand Down
5 changes: 5 additions & 0 deletions mods.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ func (m *Mods) startCompletionCmd(content string) tea.Cmd {
mod.MaxChars = cfg.MaxInputChars
}

// Check if the model is an o1 model and set the max_completion_tokens parameter accordingly
if strings.HasPrefix(mod.Name, "o1-") {
cfg.MaxTokens = cfg.MaxCompletionTokens
}

switch mod.API {
case "anthropic":
return m.createAnthropicStream(content, accfg, mod)
Expand Down