https://github.com/mutgarth/openai-rustface
A simple Rust client to interact with the OpenAI API endpoints.
https://github.com/mutgarth/openai-rustface
Last synced: 5 days ago
JSON representation
A simple Rust client to interact with the OpenAI API endpoints.
- Host: GitHub
- URL: https://github.com/mutgarth/openai-rustface
- Owner: mutgarth
- Created: 2024-12-17T01:53:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-08T02:54:25.000Z (over 1 year ago)
- Last Synced: 2025-01-08T03:27:43.194Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
- [x] 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
```