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

Support openrouter.ai #43

Closed
a-b opened this issue Nov 22, 2024 · 2 comments
Closed

Support openrouter.ai #43

a-b opened this issue Nov 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@a-b
Copy link

a-b commented Nov 22, 2024

Hi, and thanks for a fantastic product! Your POSIX approach, which enables Vim and other cli programs, speaks a lot!

Please consider adding support for the https://openrouter.ai/

I attempted to reuse Openai API

[openai]
url = "https://openrouter.ai/api/v1"
# default_model = "meta-llama/llama-3-70b-instruct"
# default_model = "openai/gpt-4o-mini"
# default_model = "google/gemini-flash-1.5"
# default_model = "anthropic/claude-3.5-sonnet:beta"
default_model = "openai/gpt-4o-mini"
api_key = "...."

but ended up with

RUST_BACKTRACE=full sc openai "hello ai"
thread 'main' panicked at /Users/ab/.cargo/registry/src/index.crates.io-6f17d22bba15001f/smartcat-2.2.0/src/utils.rs:9:30:
called `Result::unwrap()` on an `Err` value: reqwest::Error { kind: Decode, source: Error("expected value", line: 1, column: 1) }
stack backtrace:
   0:        0x105fc7148 - __mh_execute_header
   1:        0x105de490b - __mh_execute_header
   2:        0x105fc6bae - __mh_execute_header
   3:        0x105fe3d28 - __mh_execute_header
   4:        0x105fe56e5 - __mh_execute_header
   5:        0x105fca275 - __mh_execute_header
   6:        0x105fca1d9 - __mh_execute_header
   7:        0x105fe41a4 - __mh_execute_header
   8:        0x10606ff52 - __mh_execute_header
   9:        0x106070305 - __mh_execute_header
  10:        0x105d66906 - __mh_execute_header
  11:        0x105d6d1e2 - __mh_execute_header
[1]    94438 abort      RUST_BACKTRACE=full sc openai "hello ai"
@efugier
Copy link
Owner

efugier commented Nov 23, 2024

Hey, thank you for the kind words 🙂

That error is a bit weird, I'll look into it when I get some time!

@efugier efugier added the bug Something isn't working label Nov 23, 2024
@efugier efugier closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2025
@estin
Copy link

estin commented Feb 28, 2025

For other seekers.

It was invalid url in config.

There is worked example

.api_configs.toml

[openai]
api_key = "<key>"
default_model = "deepseek/deepseek-chat:free"
url = "https://openrouter.ai/api/v1/chat/completions"

promps.toml

[rust2]
api = "openai"
# char_limit = 50000

[[rust2.messages]]
role = "system"
content = """\
You are an expert programmer and a shell master. You value code efficiency and clarity above all things. \
What you write will be piped in and out of cli programs so you do not explain anything unless explicitly asked to. \
Never write ``` around your answer, never write comments, provide only the result of the task you are given. Preserve input formatting.\
"""

[[rust2.messages]]
role = "user"
# the following placeholder string #[<input>] will be replaced by the input
# each message seeks it and replaces it
content ='''Write rust code by following description. Provide only the code without any comments or explanations or markdown code wrapper.

#[<input>]
'''


[rust2]
api = "openai"
# char_limit = 50000

[[rust2.messages]]
role = "system"
content = """\
You are an expert programmer and a shell master. You value code efficiency and clarity above all things. \
What you write will be piped in and out of cli programs so you do not explain anything unless explicitly asked to. \
Never write ``` around your answer, never write comments, provide only the result of the task you are given. Preserve input formatting.\
"""

[[rust2.messages]]
role = "user"
# the following placeholder string #[<input>] will be replaced by the input
# each message seeks it and replaces it
content ='''Write rust code by following description. Provide only the code without any comments or explanations or markdown code wrapper.

#[<input>]
'''
$ sc rust2 "Give me factorial function using for loop"
fn factorial(n: u64) -> u64 {
    let mut result = 1;
    for i in 1..=n {
        result *= i;
    }
    result
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants