Skip to content

fix: correct loose config string check #147

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jdlms
Copy link
Contributor

@jdlms jdlms commented May 4, 2025

What kind of change does this PR introduce?

[x ] Bugfix
[] Feature
[] Code update (local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

If the user has no config file, and has only set their api key as an environment variable, Anthropic is always being set as the default model. If you print out the viper config after setting OPENAI_API_KEY you will see this:

 {
  "$schema": "./opencode-schema.json",
  "agents": {
    "coder": {
      "model": "claude-3.7-sonnet"
    },
    "task": {
      "model": "claude-3.7-sonnet"
    },
    "title": {
      "model": "claude-3.7-sonnet"
    }
  },

If using an OpenAI api key, this results in the following error because the max_token size is defaulting to Claude's (see #140):

│Message:                                                                                                                                  │
│  POST "https://api.openai.com/v1/chat/completions": 400 Bad Request {                                                                    │
│      "message": "max_tokens is too large: 50000. This model supports at most 32768 completion tokens, whereas you provided 50000.",      │
│      "type": "invalid_request_error",                                                                                                    │
│      "param": "max_tokens",                                                                                                              │
│      "code": "invalid_value"                                                                                                             │
│    }                                                                                                                                     │

It is happening because in config.go, viper.Get(...) returns an interface{}, and comparing that to "" is not reliable.

What is the new behavior?

Using viper.GetString, models are now correctly set based on environment variable api keys and max_tokens is no longer set to 50000 by default.

@jdlms jdlms changed the title Config fix correcting loose viper string check, default model now set… fix: correct loose config string check May 4, 2025
@rekram1-node
Copy link
Contributor

Thank you @jdlms!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants