openai_interface/rest/mod.rs
1//! REST API client module for OpenAI interface
2//!
3//! This module provides the core HTTP functionality for making requests to OpenAI-compatible APIs.
4//! It includes traits and implementations for both streaming and non-streaming API calls.
5//!
6//! # Overview
7//!
8//! The `rest` module contains:
9//! - [`post`]: HTTP POST request functionality with streaming and non-streaming support
10//! - Traits for defining API request behavior
11//! - Error handling for HTTP communication
12//!
13//! # Usage
14//!
15//! The module is designed to be used through the higher-level API modules (`chat`, `completions`,
16//! etc.). However, you can use the traits directly if needed:
17//!
18//! ```rust
19//! use openai_interface::rest::post::{NoStream, Stream};
20//! use openai_interface::errors::OapiError;
21//! use serde::{Serialize, Deserialize};
22//!
23//! use std::str::FromStr;
24//!
25//! #[derive(Serialize)]
26//! struct MyRequest {
27//! prompt: String,
28//! stream: bool,
29//! }
30//!
31//! #[derive(Deserialize)]
32//! struct MyResponse {
33//! // Define the fields of your response here
34//! id: String,
35//! }
36//!
37//! impl FromStr for MyResponse {
38//! type Err = OapiError;
39//!
40//! fn from_str(content: &str) -> Result<Self, Self::Err> {
41//! let parse_result: Result<Self, _> = serde_json::from_str(content)
42//! .map_err(|e| OapiError::DeserializationError(e.to_string()));
43//! parse_result
44//! }
45//! }
46//!
47//! impl openai_interface::rest::post::Post for MyRequest {
48//! fn is_streaming(&self) -> bool {
49//! self.stream
50//! }
51//! }
52//!
53//! impl NoStream for MyRequest {
54//! type Response = MyResponse;
55//! }
56//! // or impl Stream for MyRequest {} for streaming requests
57//! ```
58
59pub mod post;