#api-client #search #exa #find #cargo-toml #systems #metaphor

exa_api_client

用于与Exa/Metaphor系统API交互的Rust客户端

5个版本

0.1.4 2024年2月13日
0.1.3 2024年2月10日
0.1.2 2024年2月8日
0.1.1 2024年2月8日
0.1.0 2024年2月8日

43#systems

每月下载量 34次

MIT 许可证

18KB
302

Exa-rs

Crates.io Version Crates.io Total Downloads Crates.io License

Exa系统搜索API的Rust客户端。

它是使用以下API文档制作的:https://docs.exa.ai/reference/contents

安装

将 exa_api_client 添加到您的 Cargo.toml 文件中

[dependencies]
exa_api_client = "0.1.4" 

或者使用 cargo add

cargo add exa_api_client

使用它,您需要一个来自 https://docs.exa.ai/reference/getting-an-api-key 的API密钥

初始化

首先使用您的API密钥创建一个ExaApiClient实例

use exa_api_client::{ExaApiClient,SearchParams,FindSimilarParams,ContentsParams};

#[tokio::main]
async fn main() {
   let api_key = "your_api_key";
   let client: ExaApiClient = ExaApiClient::new(api_key);
}

构建器概述

ExaApiClient利用构建器模式为各种API端点构建请求参数。以下是可用构建器的概述

功能 功能 描述
搜索 SearchParams 用于构建搜索API端点的参数。
查找相似 FindSimilarParams 用于构建查找相似API端点的参数。
获取内容 ContentsParams 用于构建获取内容API端点的参数。
#[tokio::main]
async fn main() {
    let api_key = "your_api_key";
    let client: ExaApiClient = ExaApiClient::new(api_key);

let  search_params = SearchParams::new("Mitski singer")
        .use_autoprompt(true)
        .num_results(10)
        .include_domains(vec!["example.com".to_string()])
        .start_crawl_date("2023-01-01")
        .end_crawl_date("2023-12-31")
        .search_type("neural")
        .highlights(Some(5), Some(2), Some("highlight query"));

    match client.search(search_params).await {
        Ok(response) => println!("Search Response: {:?}", response),
        Err(e) => eprintln!("Error: {:?}", e),
    }}

查找相似

 // Example FindSimilarParams usage
    let find_similar = FindSimilarParams::new("https://en.wikipedia.org/wiki/Tamino_(musician)")
        .exclude_source_domain(true)
        .num_results(3)
        .text(Some(200), Some(true))
        .highlights(Some(2), Some(1), Some("related content"));

      match client.find_similar(find_similar).await {
        Ok(response) => println!("Find Similar Response:: {:?}", response),
        Err(e) => eprintln!("Error: {:?}", e),
    }

获取内容

 let contents_params = ContentsParams::new(vec!["kOYHjR-2wEIOZc9Nv4bUHQ".to_string()])
    .text(Some(100), Some(false))
    .highlights(Some(3), Some(1), Some("example query"));

    match client.contents(contents_params).await {
        Ok(response) => println!("Contents Response: {:?}", response), // Use {:?} for debug formatting
        Err(e) => eprintln!("Error: {:?}", e),
    }

示例搜索响应

Search Response: SearchResponse { results: 
[ResponseResult { title: Some("Mitski Miyawaki"), 
url: "https://mitski.fandom.com/wiki/Mitski_Miyawaki", published_date: None, author: None, id: "wx0YdyyQyjKZpim7m9kcFQ", score: Some(0.19030162692070007), text: Some(" \n\t\n\t \nMitski Miyawaki, known professionally as Mitski, born Mitsuki Laycock, was born on September 27,
 1990 in the Mie prefecture of Japan.  [1]   [2]   Before settling in the United States, Mitski lived in thirteen countries, including (but not limited to) China, Malaysia, Turkey, and the Democratic Republic of Congo. She refers to herself as 
 \"half Japanese, half American but not fully either.\"
 While attending Purchase College's Conservatory of Music to study studio composition, Mitski self-released her first two albums, Lush (2012) and Retired from Sad, New Career in Business (2013). Her senior project at Purchase originally involved the creation of these albums.
  Bury Me at Makeout Creek, her third studio album, was made available in 2014 via Double Double Whammy after she graduated. Her critically acclaimed albums Puberty 2 (2016),
  Be the Cowboy (2018), and Laurel Hell (2022), the latter of which reached the top ten in multiple countries, were then published when she signed with De"), 
  highlights: Some([" She then joined the prog-rock band Voice Coils as a vocalist while working on  Bury Me at Makeout Creek , released on Double Double Whammy as her first album on any record label.  She signed to the label Dead Oceans in 2016, and has gone on to release  Puberty 2 
   and Be the Cowboy, both to critical acclaim. In 2019 Mitski announced a hiatus from music and went on to explain on Twitter:  \"Y'all, I'm not quitting music! Me?"]),
   highlight_scores: None }], autoprompt_string: None }

贡献

我们欢迎任何反馈、贡献和建议!请在存储库的GitHub问题上提出问题或提交拉取请求。

依赖项

~6–20MB
~279K SLoC