Skip to content

A simple Rust client to interact with the OpenAI API endpoints.

Notifications You must be signed in to change notification settings

mutgarth/openai-rustface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openai-rustface

This repository provides a simple Rust client to interact with the OpenAI API. At the moment only the embeddings endpoint is enabled.

Features

  • Generate embeddings for given text.
  • Chat completions endpoint.

Requirements

  • Rust: Ensure you have Rust installed. If not, download it from rust-lang.org.
  • OpenAI API Key: Obtain an API key by signing up at OpenAI. You will need to fund your account before using it.

usage

use openai-rustface::OpenAi;

#[tokio::main]
async fn main() {
    // Replace "your_openai_api_key" with your actual API key
    let api_key = "your_openai_api_key".to_string();
    let openai_client = OpenAi::new(api_key);

    match openai_client
        .generate_embeddings("Hello, world!", "text-embedding-ada-002")
        .await
    {
        Ok(embeddings) => println!("Embeddings: {:?}", embeddings),
        Err(e) => eprintln!("Error generating embeddings: {:?}", e),
    }
}

Running tests

At the moment only one test was implemented. It uses mockito to mock the HTTP Post request.

To run the tests:

cargo test

About

A simple Rust client to interact with the OpenAI API endpoints.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages