v0.5.0 (Ergonomics)
·
187 commits
to main
since this release
New
- 0.5.0 is first most ergonomic version of this library
- All request objects can now be constructed using builder pattern
- Client exposes API "groups" for each one of (images, completions, embeddings, edits, models, fine_tunes, files) for method chaining
Notes on breaking changes
Starting with 0.5.0 I'm hoping to not have major breaking changes, as the functionality and ergonomics are better than any previous versions.
Notes to migrate from 0.4.0 and previous versions to 0.5.0
Previously on 0.4.0 and older versions
// step 1: Create client
let client = Client::new();
// step 2: Create request
let request = CreateCompletionRequest {
model: "text-ada-001".to_owned(),
prompt: Some(Prompt::String(
"Tell me a joke about the universe".to_owned(),
)),
max_tokens: Some(40),
..Default::default()
};
// step 3: Send request
let response = Completions::create(&client, request).await?;
New improved way in 0.5.0
// Use builder pattern
let client = Client::new();
// Request struct has companion builder struct with same name + Args suffix
let request = CreateCompletionRequestArgs::default()
.model("text-davinci-003")
.prompt("Tell me a joke about the universe")
.max_tokens(40_u16)
.build()?;
let response = client
.completions() // chain the API "group" (completions, images,
// embeddings, models, fine_tunes, models, edits)
.create(request).await?; // call the API on selected "group"