llm_bridge/request.rs
1//! This module defines the data models used for interacting with different LLM APIs.
2//!
3//! The main strategy employed to support multiple LLM APIs is to define separate response
4//! structs for each API (`AnthropicResponse` and `OpenAIResponse`) and use an enum
5//! (`ResponseMessage`) to represent the different response types. The `ResponseMessage` enum
6//! provides a unified interface for accessing common fields and methods across different APIs.
7//!
8//! To add support for a new LLM API:
9//! 1. Define a new response struct for the API, implementing the necessary deserialization logic.
10//! 2. Add a new variant to the `ResponseMessage` enum for the new API response type.
11//! 3. Update the implementation of the `ResponseMessage` methods to handle the new variant and
12//! provide the appropriate logic for accessing the fields and data.
13//!
14//! By following this approach, the `ResponseMessage` enum acts as a common interface for handling
15//! responses from different LLM APIs, while the individual response structs encapsulate the
16//! specific details of each API's response format.
17
18use serde::{Deserialize, Serialize};
19
20/// Represents a message in the conversation.
21#[derive(Serialize, Deserialize, Debug, Clone, Default)]
22pub struct Message {
23 pub role: String,
24 pub content: String,
25}
26
27/// Represents the request body sent to the Anthropic API.
28#[derive(Serialize, Deserialize, Debug, Default)]
29pub struct RequestBody {
30 pub model: String,
31 pub messages: Vec<Message>,
32 pub max_tokens: u32,
33 pub temperature: f32,
34 pub system: String,
35}
36
37
38
39