Code Monkey home page Code Monkey logo

openai-client's People

Contributors

akozhemiakin avatar cdxker avatar densumesh avatar dreaming-codes avatar fredriknoren avatar imotai avatar kodylow avatar perobertson avatar phayes avatar philpax avatar sjud avatar skeptrunedev avatar stintel avatar tjardoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

openai-client's Issues

Can't call dall-e-3

I get the following error:
thread 'tokio-runtime-worker' panicked at src/ai_api/api.rs:56:59:
called Result::unwrap() on an Err value: ParseError("invalid value: map, expected map with a single key")

The relevant function:

pub async fn create_image_with_prompt(prompt: &str) -> String {

    let env_variables = read_file(".env").unwrap();
    let api_key: String = (&env_variables["OPENAI_API_KEY"]).to_owned();

    let client = Client::new(api_key);
    let parameters = CreateImageParameters {
        prompt: "A cute baby dog".to_string(),
        model: Some("dall-e-3".to_string()),
        n: Some(1),
        quality: None,
        response_format: Some(ResponseFormat::Url),
        size: Some(ImageSize::Size1024X1024),
        style: None,
        user: None,
    };

    let result = client.images().create(parameters).await.unwrap();
    let paths = result.save("./images").await.unwrap();
    let models_result = client.models().list().await.unwrap();

    println!("{:#?}", models_result);
    println!("{:?}", paths);

    println!("{:#?}", result);
    return "request complete".to_string();
}

StopToken serialization issue

Greetings
When ChatCompletionParameters is serialized and stop is Some, it's serialized in "stop":{"String":"stop_text"} which causes an issue with the OpenAI APIs: EndpointError("{\n \"error\": {\n \"message\": \"{'String': '{thoughts'} is not valid under any of the given schemas - 'stop'\",\n \"type\": \"invalid_request_error\",\n \"param\": null,\n \"code\": null\n }\n}\n")

I think the issue is with how the StopToken enum is serialized.

bug: openai dive crashes server if there is a network error

Whenever OpenAI returns a 502 or doesn't respond over the network, an unwrap within the dive client fails and crashes our entire web server. We are currently on openai-dive 0.4.6

image

The fix is probably changing the unwrap at

.unwrap();
to be an unwrap_or or adding other error handling and retry logic.

We may get to pring this soon, but wanted to create the issue for visibility.

Feature Request: Expose OpenAI Rate Limiting Headers

I'm currently using openai_dive in a project to simplify my usage of the OpenAI API.. One thing that might be useful to the wider user base would be access to the Rate Limiting Headers as described in the OpenAI Docs specifically they mention x-ratelimit-limit-requests, x-ratelimit-limit-tokens,x-ratelimit-remaining-requests,x-ratelimit-remaining-tokens,x-ratelimit-reset-requests, and x-ratelimit-reset-tokens. Those all sound very useful for backing off the API appropriately.
Would you consider exposing the return headers in the various response objects?

How to submit a run action?

Hi, thanks for the work on this library.
How do I submit a run tool output after my RunStatus becomes RequiresAction?

`APIError::EndpointError` should include status code

At present, EndpointError is constructed using just the text of the response:

if !response.status().is_success() {
return Err(APIError::EndpointError(response.text().await.unwrap()));
}

Ideally, this would also return the status code so that the calling code can decide what to do with the failure (i.e. if it's a 5xx error, the request could be retried; if it's a rate limit, the code could wait a bit.)

I'm also not sure validate_response (below that code) is called anywhere, and given that check_status_code will return an EndpointError for any successful responses, it's not clear that there could be an opportunity for it to be called. It seems like these two functions should be merged so that specific errors from the OpenAI API can be surfaced, while non-specific errors can be dealt with based on the status code.

Unwrap panic

thread '<unnamed>' panicked at /Users/sjud/.cargo/registry/src/index.crates.io-6f17d22bba15001f/openai_dive-0.3.5/src/v1/resources/shared.rs:109:18:

for reference

 x_ratelimit_limit_requests: value
                .get("x-ratelimit-limit-requests")
                .unwrap()

I can make a pull request for error handling here if helpful?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.