-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use reqwest::header::{HeaderMap, HeaderValue}; | ||
use reqwest::{Client, Error}; | ||
use serde_json::{Value, json}; | ||
use std::collections::HashMap; | ||
|
||
|
||
pub async fn generate_embed(key: &String, texts: &Vec<String>) -> Result<Value, Error>{ | ||
let client = Client::new(); | ||
|
||
let mut params: HashMap<&str, Value> = HashMap::new(); | ||
|
||
params.insert("model", "embed-english-light-v3.0".into()); | ||
params.insert("texts", json!(texts)); | ||
params.insert("input_type", "search_document".into()); | ||
|
||
// let json_params = json!(params); | ||
|
||
let response = client.post("https://api.cohere.ai/v1/embed") | ||
.header("Content-Type", "application/json") | ||
.header("Authorization", format!("Bearer {}", key)) | ||
.json(¶ms) | ||
.send() | ||
.await?; | ||
|
||
Ok(response.json().await?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod embed; | ||
pub mod rerank; | ||
pub mod sum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use reqwest::header::{HeaderMap, HeaderValue}; | ||
use reqwest::{Client, Error}; | ||
use serde_json::{Value, json}; | ||
use std::collections::HashMap; | ||
|
||
|
||
pub async fn rerank(key: &String, query: &String, page: &Vec<String>) -> Result<Value, Error>{ | ||
let client = Client::new(); | ||
|
||
let mut params: HashMap<&str, Value> = HashMap::new(); | ||
|
||
params.insert("model", "rerank-english-v2.0".into()); | ||
// convert query to value | ||
params.insert("query", json!(query)); | ||
params.insert("top_n", 3.into()); // default to 5 in production | ||
params.insert("documents", json!(page)); | ||
|
||
let response = client.post("https://api.cohere.ai/v1/rerank") | ||
.header("Content-Type", "application/json") | ||
.header("Authorization", format!("Bearer {}", key)) | ||
.json(¶ms) | ||
.send() | ||
.await?; | ||
|
||
Ok(response.json().await?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use reqwest::header::{HeaderMap, HeaderValue}; | ||
use reqwest::{Client, Error}; | ||
use serde_json::{Value, json}; | ||
use std::collections::HashMap; | ||
|
||
|
||
pub async fn summarize(key: &String, page: &String) -> Result<Value, Error>{ | ||
let client = Client::new(); | ||
|
||
let mut params: HashMap<&str, Value> = HashMap::new(); | ||
|
||
params.insert("preamble", "Summarize the webpage so that it can be retrieved later.".into()); | ||
params.insert("message", json!(page)); | ||
|
||
let response = client.post("https://api.cohere.ai/v1/chat") | ||
.header("Content-Type", "application/json") | ||
.header("Authorization", format!("Bearer {}", key)) | ||
.json(¶ms) | ||
.send() | ||
.await?; | ||
|
||
Ok(response.json().await?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters