Skip to main content

exa_async/types/
answer.rs

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