Struct KagiClient

Source
pub struct KagiClient {
    pub config: KagiConfig,
    pub inner_client: ClientWithMiddleware,
}

Fields§

§config: KagiConfig§inner_client: ClientWithMiddleware

Implementations§

Source§

impl KagiClient

Source

pub fn new(config: KagiConfig) -> Self

Create a KagiClient for a given KagiConfig and reqwest::Client.

Examples found in repository?
examples/simple-fastgpt.rs (line 6)
4async fn main() {
5    let config = kagi_api::KagiConfig::with_api_key("api key goes here");
6    let client = kagi_api::KagiClient::new(config);
7
8    let use_cache = true;
9    let answer = client
10        .fastgpt("How do I entertain my cat?", use_cache)
11        .await
12        .expect("A valid FastGPT search result");
13
14    // FIXME: Cannot `.render()` without kagi-cli: Remove `Render` trait's coupling from `Args`.
15    serde_json::to_writer_pretty(std::io::stdout(), &answer).unwrap();
16}
More examples
Hide additional examples
examples/simple-summary.rs (line 6)
4async fn main() {
5    let config = kagi_api::KagiConfig::with_api_key("api key goes here");
6    let client = kagi_api::KagiClient::new(config);
7    let options = SummaryOptions::default();
8
9    let some_url = url::Url::parse("https://en.wikipedia.org/wiki/A_Cyborg_Manifesto").unwrap();
10    let summary = client
11        .summarize_url(some_url, options)
12        .await
13        .expect("A valid Universal Summarizer result");
14
15    // FIXME: Cannot `.render()` without kagi-cli: Remove `Render` trait's coupling from `Args`.
16    serde_json::to_writer_pretty(std::io::stdout(), &summary).unwrap();
17}
Source

pub fn with_replay( config: KagiConfig, reqwest_client: Client, record_replay_mode: RecordReplayMode, ) -> KagiResult<Self>

Create a KagiClient for a given KagiConfig and reqwest::Client.

Use rvcr::VCRMiddleware to log request/response to disk.

FIXME: Mention KAGI_API_LOGDIR.

FIXME: Avoid panics from rvcr by fixing them upstream.

Source

pub async fn query<Q>( &self, endpoint: &str, request_body: Q, ) -> KagiResult<Response>
where Q: Serialize,

Trait Implementations§

Source§

impl FastGPT for KagiClient

Source§

fn fastgpt<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, cache: bool, ) -> Pin<Box<dyn Future<Output = KagiResult<Answer>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl UniversalSummarizer for KagiClient

Source§

fn summarize<'life0, 'async_trait>( &'life0 self, subject: Subject, options: SummaryOptions, ) -> Pin<Box<dyn Future<Output = KagiResult<Summary>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn summarize_url<'life0, 'async_trait>( &'life0 self, url: Url, options: SummaryOptions, ) -> Pin<Box<dyn Future<Output = KagiResult<Summary>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Source§

fn summarize_text<'life0, 'async_trait>( &'life0 self, text: String, options: SummaryOptions, ) -> Pin<Box<dyn Future<Output = KagiResult<Summary>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,