tjardoo / openai-client Goto Github PK
View Code? Open in Web Editor NEWOpenAI Dive is an unofficial async Rust library that allows you to interact with the OpenAI API.
Home Page: https://crates.io/crates/openai_dive
License: MIT License
OpenAI Dive is an unofficial async Rust library that allows you to interact with the OpenAI API.
Home Page: https://crates.io/crates/openai_dive
License: MIT License
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();
}
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.
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
The fix is probably changing the unwrap at
Line 123 in 962d0fa
We may get to pring this soon, but wanted to create the issue for visibility.
How do you get the tool call id, or the id of the tool?
Tool output has this field
tool_call_id: Option<String>
The ID of the tool call in the ‘required_action’ object within the run object the output is being submitted for.
But, the run object doesn't have a required_action object
https://platform.openai.com/docs/api-reference/runs/object
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?
https://platform.openai.com/docs/api-reference/fine-tunes/create
cargo fmt -- --check
cargo fmt
Hi, thanks for the work on this library.
How do I submit a run tool output after my RunStatus becomes RequiresAction?
Hi there,
I'm thinking of implementing function calling (https://openai.com/blog/function-calling-and-other-api-updates), but I don't want to step on toes if this is already being implemented. Are there any current plans to support function calling? If not, I'll add support.
Hey @tjardoo
Are there any current plans to support OpenAI Vision API?
https://platform.openai.com/docs/guides/vision
Please let me know. Was thinking to raise a PR if so. Thank you.
At present, EndpointError
is constructed using just the text of the response:
openai-client/src/v1/helpers.rs
Lines 14 to 16 in b99e9f7
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.