Skip to content

Commit

Permalink
add doc example
Browse files Browse the repository at this point in the history
  • Loading branch information
anchpop committed Dec 27, 2024
1 parent de73121 commit 07e3df8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

**Typed OpenAI Chat Completions in Rust**

[tysm on crates.io](https://crates.io/crates/tysm)

[tysm on docs.rs](https://docs.rs/tysm/latest/tysm/)

## Table of Contents
- [tysm - Thank You So Much](#tysm---thank-you-so-much)
- [Table of Contents](#table-of-contents)
Expand Down
52 changes: 52 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,64 @@
//! .unwrap();
//!
//! assert_eq!(name.first, "George");
//! assert_eq!(name.last, "Washington");
//! }
//! ```
//!
//! Alternative name: **T**yped **S**chema **M**agic.
//!
//! ```rust,no_run
//! use tysm::ChatClient;
//!
//! // Create a client from a `OPENAI_API_KEY` environment variable
//! let client = ChatClient::from_env("gpt-4o");
//! // or pass in your API key explicitly
//! let client = ChatClient::new("sk-1234567890", "gpt-4o");
//!
//! // Define your response struct
//! #[derive(serde::Deserialize, Debug, schemars::JsonSchema)]
//! struct CityName {
//! english: String,
//! local: String,
//! }
//!
//! # tokio_test::block_on(async {
//! // Send a chat message to the API and deserialize the response into your struct
//! let response: CityName = client.chat("What is the capital of Portugal?").await.unwrap();
//!
//! assert_eq!(response.english, "Lisbon");
//! assert_eq!(response.local, "Lisboa");
//! # })

#![deny(missing_docs)]

mod chatgpt;
Expand Down

0 comments on commit 07e3df8

Please sign in to comment.