16 releases

new 1.0.0-alpha.18 Dec 22, 2024
1.0.0-alpha.16 Aug 27, 2024
1.0.0-alpha.15 Jul 15, 2024
1.0.0-alpha.14 Feb 22, 2024
0.4.1 Feb 24, 2017

#40 in Machine learning

Download history 474/week @ 2024-09-04 714/week @ 2024-09-11 323/week @ 2024-09-18 403/week @ 2024-09-25 322/week @ 2024-10-02 238/week @ 2024-10-09 301/week @ 2024-10-16 305/week @ 2024-10-23 482/week @ 2024-10-30 355/week @ 2024-11-06 458/week @ 2024-11-13 697/week @ 2024-11-20 315/week @ 2024-11-27 354/week @ 2024-12-04 439/week @ 2024-12-11 410/week @ 2024-12-18

1,788 downloads per month
Used in 9 crates (7 directly)

MIT license

84KB
1.5K SLoC

openai

crates.io Rust workflow

An unofficial Rust library for the OpenAI API.

Warning

There may be breaking changes between versions while in alpha. See Implementation Progress.

Examples

Examples can be found in the examples directory.

Please note that examples are not available for all the crate's functionality, PRs are appreciated to expand the coverage.

Currently, there are examples for the completions module and the chat module. For other modules, refer to the tests submodules for some reference.

Chat Example

// Relies on OPENAI_KEY and optionally OPENAI_BASE_URL.
let credentials = Credentials::from_env();
let messages = vec![
    ChatCompletionMessage {
        role: ChatCompletionMessageRole::System,
        content: Some("You are a helpful assistant.".to_string()),
        name: None,
        function_call: None,
    },
    ChatCompletionMessage {
        role: ChatCompletionMessageRole::User,
        content: Some("Tell me a random crab fact".to_string()),
        name: None,
        function_call: None,
    },
];
let chat_completion = ChatCompletion::builder("gpt-4o", messages.clone())
    .credentials(credentials.clone())
    .create()
    .await
    .unwrap();
let returned_message = chat_completion.choices.first().unwrap().message.clone();
// Assistant: Sure! Here's a random crab fact: ...
println!(
    "{:#?}: {}",
    returned_message.role,
    returned_message.content.unwrap().trim()
);

Implementation Progress

██████████ Models

████████░░ Completions (Function calling is supported)

████████░░ Chat

██████████ Edits

░░░░░░░░░░ Images

█████████░ Embeddings

░░░░░░░░░░ Audio

███████░░░ Files

░░░░░░░░░░ Fine-tunes

██████████ Moderations

Contributing

All contributions are welcome. Unit tests are encouraged.

Fork Notice

This package was initially developed by Valentine Briese. As the original repo was archived, this is a fork and continuation of the project.

Dependencies

~8–20MB
~265K SLoC