Skip to content

Commit

Permalink
docs (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop authored Dec 26, 2024
1 parent 9334865 commit 9d75f05
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ jobs:
- name: Run tests
run: cargo test --verbose

- name: Build docs
run: cargo doc --no-deps

- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tysm"
version = "0.2.9"
version = "0.2.10"
edition = "2021"
description = "Typed OpenAI Chat Completions"
license = "MIT"
Expand All @@ -19,7 +19,7 @@ serde_json = "1.0.107"
thiserror = "2.0.9"
tynm = "0.1.10"
lru = "0.12.5"
schemars = { git = "https://github.com/GREsau/schemars.git", version = "1.0.0-alpha.17", features = [
schemars = { git = "https://github.com/GREsau/schemars.git", features = [
"preserve_order",
] }

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# tysm
# tysm - Thank You So Much

**Typed OpenAI Chat Completions in Rust**

## Table of Contents
- [tysm](#tysm)
- [tysm - Thank You So Much](#tysm---thank-you-so-much)
- [Table of Contents](#table-of-contents)
- [Usage](#usage)
- [Features](#features)
Expand Down
3 changes: 3 additions & 0 deletions src/chatgpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ impl ChatClient {
/// It will also look in the `.env` file for an `OPENAI_API_KEY` variable (using dotenv).
///
/// ```rust
/// # use tysm::ChatClient;
/// let client = ChatClient::from_env("gpt-4o").unwrap();
/// ```
pub fn from_env(model: impl Into<String>) -> Result<Self, OpenAiApiKeyError> {
Ok(Self::new(api_key()?, model))
}
Expand Down
44 changes: 42 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
//! A simple library to interact with the ChatGPT API.
//! # `tysm` - Thank You So Much
//!
//! It uses the [schemars](https://docs.rs/schemars/latest/schemars/index.html) crate to generate a schema for the desired response type.
//! Typed OpenAI Chat Completions.
//!
//! A strongly-typed Rust client for OpenAI's ChatGPT API that enforces type-safe responses using [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
//!
//! This library uses the [schemars](https://docs.rs/schemars/latest/schemars/index.html) crate to generate a schema for the desired response type. It also uses [serde](https://docs.rs/serde/latest/serde/index.html) to deserialize the response into the desired type. Install these crates like so:
//!
//! 1. `cargo add serde`.
//! 2. `cargo add --git https://github.com/GREsau/schemars.git schemars`
//!
//! ## Usage
//!
//! ```rust,ignore
//! use tysm::ChatClient;
//!
//! // We want names separated into `first` and `last`.
//! #[derive(serde::Deserialize, schemars::JsonSchema)]
//! struct Name {
//! first: String,
//! last: String,
//! }
//!
//! async fn get_president_name() {
//! // Create a client.
//! // `from_env` will look for an API key under the environment
//! // variable "OPENAI_API_KEY"
//! // It will also look inside `.env` if such a file exists.
//! let client = ChatClient::from_env("gpt-4o").unwrap();
//!
//! // Request a chat completion from OpenAI and
//! // parse the response into our `Name` struct.
//! let name: Name = client
//! .chat("Who was the first US president?")
//! .await
//! .unwrap();
//!
//! assert_eq!(name.first, "George");
//! assert_eq!(name.last, "Washington");
//! }
//! ```
//!
//! Alternative name: **T**yped **S**chema **M**agic.
#![deny(missing_docs)]

Expand Down

0 comments on commit 9d75f05

Please sign in to comment.