Skip to main content

exa_async/types/
answer.rs

1//! Types for the Exa `/answer` endpoint (non-streaming)
2
3use serde::Deserialize;
4use serde::Serialize;
5
6/// Request body for `POST /answer`
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct AnswerRequest {
10    /// The query to answer
11    pub query: String,
12
13    /// Model to use (e.g., "exa" or "exa-pro")
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub model: Option<String>,
16
17    /// System prompt to guide the answer
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub system_prompt: Option<String>,
20
21    /// Text to display when streaming (non-streaming only uses query)
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub text: Option<bool>,
24}
25
26impl AnswerRequest {
27    /// Create a new answer request with the given query
28    #[must_use]
29    pub fn new(query: impl Into<String>) -> Self {
30        Self {
31            query: query.into(),
32            model: None,
33            system_prompt: None,
34            text: None,
35        }
36    }
37
38    /// Set the model
39    #[must_use]
40    pub fn with_model(mut self, model: impl Into<String>) -> Self {
41        self.model = Some(model.into());
42        self
43    }
44}
45
46/// A citation in an answer response
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct Citation {
50    /// URL of the cited source
51    pub url: String,
52    /// Title of the cited source
53    #[serde(default)]
54    pub title: Option<String>,
55    /// ID of the cited source
56    #[serde(default)]
57    pub id: Option<String>,
58    /// Published date
59    #[serde(default)]
60    pub published_date: Option<String>,
61    /// Author
62    #[serde(default)]
63    pub author: Option<String>,
64}
65
66/// Response from `POST /answer` (non-streaming)
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(rename_all = "camelCase")]
69pub struct AnswerResponse {
70    /// The generated answer
71    pub answer: String,
72
73    /// Citations used in the answer
74    #[serde(default)]
75    pub citations: Vec<Citation>,
76
77    /// Cost in dollars
78    #[serde(default)]
79    pub cost_dollars: Option<super::search::CostDollars>,
80}