1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2025 Michael Dippery <michael@monkey-robot.com>
//! **Cogito:** Helping you produce AI slop with large language models
//! since 2025.
//!
//! Cogito provides a uniform interface to AI service providers such as
//! OpenAI and Anthropic Claude, including an abstract representation of
//! an [`AiModel`], an [`AIClient`]( providing a high-level interface to an
//! AI service, an [`AIRequest`] to represent common features of AI services,
//! and a [`Service`] to represent connectivity over HTTP (or other protocols)
//! or allow testing code to easily mock an AI service. These building blocks
//! make it easy for you to implement individual clients for specific AI
//! service providers. You can then build your application using these
//! provider implementations, making it easy to switch out providers in your
//! application without changing more than few `use` statements.
//!
//! # Design
//!
//! The heart and soul of Cogito (if an artificial intelligence module can be
//! said to have either a heart or a soul) is [`AIClient`]. `AIClient` exposes
//! a single method, [`send()`], which sends an [`AIRequest`] to an AI
//! service's API (probably by using an underlying HTTP [`Service`] instance).
//!
//! If `AIClient` is the heart and soul of Cogito, `AIRequest` is the meat
//! and bones. `AIRequest` instances represent the generalized features of
//! an AI service, such as [model specification], [system prompts], and of
//! course [input]. Each AI provider defines its own `AIRequest` type,
//! making it easy to implement specific functionality behind a uniform
//! interface. Similarly, each AI provider can implement [`AIResponse`] to
//! handle responses from its associated API, returning data in a uniform way.
//!
//! Finally, [`Service`] can be used to provide different low-level ways of
//! communicating with the AI service's API. Often times this will consist
//! of an HTTP service that talks to a live API, as well as a test API
//! service that can be used for mocking API calls during tests.
//!
//! All of these traits, of course, are generally implemented by individual
//! provider crates, such as [cogito-openai], so you rarely need to work
//! with these data types directly, unless you are implementing a client
//! for an AI service.
//!
//! [`AIClient`]: client::AiClient
//! [`AIRequest`]: client::AiRequest
//! [`AIResponse`]: client::AiResponse
//! [`Service`]: service::Service
//! [`send()`]: client::AiClient::send
//! [model specification]: client::AiRequest::model
//! [system prompts]: client::AiRequest::instructions
//! [input]: client::AiRequest::input
//! [cogito-openai]: https://docs.rs/cogito-openai
use Debug;
/// Represents an AI model.
///
/// This representation is fairly abstract: rather than exposing specific
/// models like GPT-5 or Sonnet 4.5, it provides access through conceptual
/// classes like "flagship", "best", "cheapest", and "fastest". Individual
/// provider implementations can make these classes to actual models,
/// which also allows providers to easily change the underlying model
/// represented by a given class. For example, when GPT-6 comes out,
/// an OpenAI provider could re-map "flagship" to GPT-6, allowing all users
/// of the provider to upgrade without changing any code.
///
/// # Examples
///
/// Often this trait is applied to an enum that represents a provider's
/// concrete models. For example:
///
/// ```
/// # use cogito::AiModel;
/// #
/// #[derive(Clone, Copy, Debug, Default)]
/// pub enum ApocalypticAI {
/// #[default]
/// AM,
/// Skynet,
/// HAL9000,
/// TheMachines,
/// Cylons,
/// }
///
/// impl AiModel for ApocalypticAI {
/// fn flagship() -> Self {
/// ApocalypticAI::default()
/// }
///
/// fn best() -> Self {
/// ApocalypticAI::TheMachines
/// }
///
/// fn cheapest() -> Self {
/// ApocalypticAI::HAL9000
/// }
///
/// fn fastest() -> Self {
/// ApocalypticAI::Cylons
/// }
/// }
/// ```
/// Convenience module for the most common Cogito imports.
///
/// # Example
///
/// Add
///
/// ```
/// use cogito::prelude::*;
/// ```
///
/// to use the most common Cogito traits and data structures in your project.