ante-llm 0.4.2

Streaming LLM client for Anthropic, OpenAI, Gemini and Chat Completions servers, from the Ante coding agent
Documentation
// Copyright 2026 Antigma Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Web search through a provider's own API, apart from its chat client.
//!
//! Most providers serve search as one chat request with a hosted search tool
//! switched on; DeepSeek serves it from an endpoint of its own. Either way a
//! search needs the provider's transport and nothing else a chat client
//! holds, so it is built beside the chat client rather than reached through
//! it.

mod deepseek;

use crate::openai_compatible::OpenAiCompatProfile;

use super::client::Client;
use super::error::LlmError;
use super::types::{ModelSpec, WebSearchResult};
use super::{anthropic, gemini, openai, openai_compatible};

/// How a provider's endpoint serves web search.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SearchStyle {
    /// The Messages API with Anthropic's hosted search tool.
    Anthropic,
    /// The Responses API with its hosted search tool, read as a stream: the
    /// platform endpoint serves one, and the ChatGPT subscription endpoint
    /// serves nothing else.
    OpenAiResponses,
    /// `generateContent` grounded in Google Search.
    Gemini,
    /// Chat completions carrying the search parameters of the model's profile.
    OpenAiCompatible(OpenAiCompatProfile),
    /// DeepSeek's search endpoint: a query in, ranked results out, no model.
    DeepSeek,
}

impl SearchStyle {
    /// The search an OpenAI-compatible provider serves with a model, if any.
    /// DeepSeek's own API serves it from an endpoint beside chat, whatever
    /// the model; elsewhere the model's profile names the chat parameters.
    pub fn openai_compatible(provider_id: &str, model_id: &str) -> Option<Self> {
        if provider_id.eq_ignore_ascii_case("deepseek") {
            return Some(Self::DeepSeek);
        }
        let profile = OpenAiCompatProfile::from_model(provider_id, model_id);
        profile.supports_search().then_some(Self::OpenAiCompatible(profile))
    }
}

/// One provider's web search: its transport, the style of search its
/// endpoint serves, and the model a hosted search runs on.
pub struct SearchClient {
    transport: Client,
    style: SearchStyle,
    model: ModelSpec,
}

impl SearchClient {
    /// A search over `transport` in `style`. A hosted search runs on `model`.
    pub fn new(transport: Client, style: SearchStyle, model: ModelSpec) -> Self {
        Self { transport, style, model }
    }

    pub async fn search(&self, query: &str) -> Result<WebSearchResult, LlmError> {
        let (transport, model) = (&self.transport, &self.model);
        match self.style {
            SearchStyle::Anthropic => anthropic::search(transport, query, model).await,
            SearchStyle::OpenAiResponses => openai::search(transport, query, model).await,
            SearchStyle::Gemini => gemini::search(transport, query, model).await,
            SearchStyle::OpenAiCompatible(profile) => {
                openai_compatible::search(transport, query, model, profile).await
            }
            SearchStyle::DeepSeek => deepseek::search(transport, query).await,
        }
    }
}