dongri / openai-api-rs

OpenAI API client library for Rust (unofficial)
https://docs.rs/openai-api-rs
MIT License
309 stars 53 forks source link

Error 404 #85

Closed oblivisheee closed 6 months ago

oblivisheee commented 6 months ago

Describe the bug

When I try to run a completion, I get a 404 error. I am using API of NagaAI - https://api.naga.ac/v1. When I use NagaAI with the official Python library it doesn't make any errors.

To Reproduce

  1. Get a prompt and a client
  2. Run a completion
  3. Return generated text

Code snippets

use openai_api_rs::v1::api::Client;
use openai_api_rs::v1::completion::{self, CompletionRequest, CompletionResponse};
pub fn get_completion(client: Client, prompt: &str) -> String {
    let prompt_string = String::from(prompt);
    let req = CompletionRequest::new(String::from("gpt-3.5-turbo"), prompt_string)
        .max_tokens(3000)
        .temperature(0.9)
        .top_p(1.0)
        .stop(vec![String::from(" Human:"), String::from(" AI:")])
        .presence_penalty(0.6)
        .frequency_penalty(0.0);

    let result = client.completion(req).unwrap(); // Error location
    result.choices[0].text.clone()
}

pub fn client(api: &str) -> Client {
    let api_data = String::from(api);
    const BASE_URL: &str = "https://api.naga.ac/v1";
    let endpoint = std::env::var("OPENAI_API_BASE").unwrap_or_else(|_| BASE_URL.to_owned());
    Client::new_with_endpoint(endpoint, api_data)
}

OS

macOS

Rust version

Rust v1.75.0

Library version

openai-api-rs 4.0.8

oblivisheee commented 6 months ago

I figured out how to fix it.