Communicate with OpenAi's GPT3.5 (ChatGPT) API.

Overview

ChatGPT Rust

Communicate with OpenAi's GPT3.5 (ChatGPT) API.

Usage

use chat_gpt_rs::prelude::*;

#[tokio::main]
async fn main() {
    let token = Token::new("YOUR_API_KEY");
    let api = Api::new(token);
    let request = Request {
        model: Model::Gpt35Turbo,
        messages: vec![Message {
            role: "user".to_string(),
            content: "Hello, how's it going?".to_string(),
        }],
        ..Default::default()
    };
    let response = api.chat(request).await;
    if let Ok(response) = response {
        println!("{:?}", response.choices[0].message.content);
    } else {
        println!("Error: {:?}", response.err());
    }
}   

Additional Configuration

Following configuration options are available in the Request struct:

  • Model: ID of the model to use. Currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported.
  • Messages: messages to generate chat completions for, in the chat format.
  • Temperature: what sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
  • TopP: an alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
  • N: how many chat completion choices to generate for each input message.
  • Stop: up to 4 sequences where the API will stop generating further tokens.
  • MaxTokens: maximum number of tokens to generate for each chat completion choice.
  • PresencePenalty: a number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
  • FrequencyPenalty: a number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
  • User: a unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Providing Organization ID

You may provide your OpenAI organization ID when creating the API instance.

    let api = Api::new(token).with_organization_id("YOUR_ORGANIZATION_ID")
You might also like...
Stream-based FSEvents API bindings.

fsevent-stream Stream-based FSEvents API bindings. Features Support directory-granular and file-granular events. Retrieve related file inode with kFSE

ncnn Rust API.

rust-ncnn ncnn Rust API. Prequisition Rust Env $ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh CMake = 3.12 Rust cmake needs --paral

Interact with the crate's API

cargo-api Interact with the crate's API Documentation Installation Getting Started Reference FAQ Contribute CHANGELOG Install Download a pre-built bin

This article is about the unsound api which I found in owning_ref. Owning_ref is a library that has 11 million all-time downloads and 60 reverse dependencies.

Unsoundness in owning_ref This article is about the unsound api which I found in owning_ref. Owning_ref is a library that has 11 million all-time down

weggli-native a "native" C API for Google's weggli

weggli-native a "native" C API for Google's weggli

Manage self-hosted Supabase instances with an easy to use API & Web Portal (soon)

SupaManager A project by Harry Bairstow; Manage self-hosted Supabase instances with an easy to use API & Web Portal (soon) ⚠️ Note: The project is in

Rust crate for creating filters with DirectX shaders. Includes Scale, Color conversion using DirectX api.

DxFilter Scale and ColorConversion done with DirectX filters. You can also create your own filters with the provided api. Crate contains various tools

Examples of how to use Rust with Serverless Framework, Lambda, API Gateway v1 and v2, SQS, GraphQL, etc

Rust Serverless Examples All examples live in their own directories: project: there is nothing here, just a simple cargo new project_name with a custo

Bindings to the Tauri API for projects using wasm-bindgen

tauri-sys Raw bindings to the Tauri API for projects using wasm-bindgen Installation This crate is not yet published to crates.io, so you need to use

Releases(v1.2.0)
Owner
Aiden
The most enjoyable hobby of my life is also my profession | Full-Stack Software Engineer | CSUF Engineering Alumni
Aiden
Generate commit messages using GPT3 based on your changes and commit history.

Commit Generate commit messages using GPT-3 based on your changes and commit history. Install You need Rust and Cargo installed on your machine. See t

Brian Le 40 Jan 3, 2023
🔮 ChatGPT Desktop Application (Mac, Windows and Linux)

ChatGPT ChatGPT Desktop Application ?? Install ?? Update Log ?? History versions... Windows From our github releases: ChatGPT_0.7.4_x64_en-US.msi Or i

lencx 3.8k Jan 6, 2023
OpenAI ChatGPT desktop app for Mac, Windows, & Linux menubar using Tauri & Rust

ChatGPT Desktop App Unofficial open source OpenAI ChatGPT desktop app for mac, windows, and linux menubar using tauri & rust. Downloads Windows (2.7 M

Sonny Lazuardi 732 Jan 5, 2023
A simple omegle API written in Rust

omegalul-rs omegalul-rs is a work-in-progress opensource library for building Omegle clients. Features Current Features Fetching random server from om

NV6 5 Jun 21, 2022
Simple fake AWS Cognito User Pool API server for development.

Fakey Cognito ?? Homepage Simple fake AWS Cognito API server for development. ✅ Implemented features AdminXxx on User Pools API. Get Started # run wit

naokirin 4 Aug 30, 2022
High level rust abstractions for the libretro API

libretro-rs Design Philosophy The approach to this crate can best be summarized as wanting to expose all functionality, even if not idiomatically. The

null 9 Dec 25, 2022
Femtorinth is a library to interact with a sub-set of the Modrinth API.

Femtorinth Femtorinth is a rust library to interact with a sub-set of the Modrinth api, it only includes the api calls that don't need auth (a.k.a onl

null 2 May 6, 2022
Rust library for interacting with the VTube Studio API

vtubestudio-rs A library for interacting with the VTube Studio API. Basic usage This example creates a Client using the provided builder, which: conne

null 6 Dec 4, 2022
C API to SpringQL (for embedded mode)

SpringQL C Client This repository is a C client for SpringQL and provides it provides: springql.h: C header file. libspringql_client.{so,dylib}: Share

SpringQL 4 Jun 8, 2022
⚡️ Fast MagicString port driven by Rust and N-API

magic-string-rs 100% API compatible (port) MagicString by Rich-Harris implementation for Node and modern browsers, also, for rust, of course. Installa

Hana 35 Nov 21, 2022