valentinegb / openai

An unofficial Rust library for the OpenAI API.
https://crates.io/crates/openai/
MIT License
61 stars 18 forks source link

Create builders for `Completion` and `Edit` structures #21

Closed valentinegb closed 1 year ago

valentinegb commented 1 year ago

This pull requests adds CompletionBuilder and EditBuilder, which allows you to create completions and edits with the builder pattern. There are no builder structures for other structures like Embeddings and Model because they don't have very many fields. Here is an example of making a Completion with this PR:

let completion = Completion::builder()
    .model(ModelID::TextDavinci003)
    .prompt("Say this is a test")
    .max_tokens(7)
    .temperature(0.0)
    .create()
    .await
    .unwrap()
    .unwrap();