mirror of https://github.com/buster-so/buster.git
Merge branch 'main' into staging
This commit is contained in:
commit
f7df68880e
|
@ -9,32 +9,22 @@ pub struct Reranker {
|
||||||
base_url: String,
|
base_url: String,
|
||||||
model: String,
|
model: String,
|
||||||
client: Client,
|
client: Client,
|
||||||
environment: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reranker {
|
impl Reranker {
|
||||||
pub fn new() -> Result<Self, Box<dyn Error>> {
|
pub fn new() -> Result<Self, Box<dyn Error>> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let environment = env::var("ENVIRONMENT").unwrap_or_else(|_| "production".to_string());
|
|
||||||
|
let api_key = env::var("RERANK_API_KEY")?;
|
||||||
// If local environment, we don't need these values
|
let model = env::var("RERANK_MODEL")?;
|
||||||
let (api_key, model, base_url) = if environment == "local" {
|
let base_url = env::var("RERANK_BASE_URL")?;
|
||||||
(String::new(), String::new(), String::new())
|
|
||||||
} else {
|
|
||||||
(
|
|
||||||
env::var("RERANK_API_KEY")?,
|
|
||||||
env::var("RERANK_MODEL")?,
|
|
||||||
env::var("RERANK_BASE_URL")?,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
api_key,
|
api_key,
|
||||||
base_url,
|
base_url,
|
||||||
model,
|
model,
|
||||||
client,
|
client,
|
||||||
environment,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +34,13 @@ impl Reranker {
|
||||||
documents: &[&str],
|
documents: &[&str],
|
||||||
top_n: usize,
|
top_n: usize,
|
||||||
) -> Result<Vec<RerankResult>, Box<dyn Error>> {
|
) -> Result<Vec<RerankResult>, Box<dyn Error>> {
|
||||||
// Otherwise use the remote API
|
|
||||||
let request_body = RerankRequest {
|
let request_body = RerankRequest {
|
||||||
query: query.to_string(),
|
query: query.to_string(),
|
||||||
documents: documents.iter().map(|s| s.to_string()).collect(),
|
documents: documents.iter().map(|s| s.to_string()).collect(),
|
||||||
top_n,
|
top_n,
|
||||||
model: self.model.clone(),
|
model: self.model.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
.post(&self.base_url)
|
.post(&self.base_url)
|
||||||
|
@ -58,6 +48,7 @@ impl Reranker {
|
||||||
.json(&request_body)
|
.json(&request_body)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let response_body: RerankResponse = response.json().await?;
|
let response_body: RerankResponse = response.json().await?;
|
||||||
Ok(response_body.results)
|
Ok(response_body.results)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue