mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-05-15 16:53:57 +02:00
Support overwriten prompts of the search query
This commit is contained in:
parent
e5c963a170
commit
ac39a436d9
@ -53,8 +53,8 @@ use flate2::Compression;
|
|||||||
use meilisearch_types::batches::Batch;
|
use meilisearch_types::batches::Batch;
|
||||||
use meilisearch_types::features::{InstanceTogglableFeatures, Network, RuntimeTogglableFeatures};
|
use meilisearch_types::features::{InstanceTogglableFeatures, Network, RuntimeTogglableFeatures};
|
||||||
use meilisearch_types::heed::byteorder::BE;
|
use meilisearch_types::heed::byteorder::BE;
|
||||||
use meilisearch_types::heed::types::I128;
|
use meilisearch_types::heed::types::{Str, I128};
|
||||||
use meilisearch_types::heed::{self, Env, RoTxn, WithoutTls};
|
use meilisearch_types::heed::{self, Database, Env, RoTxn, WithoutTls};
|
||||||
use meilisearch_types::milli::index::IndexEmbeddingConfig;
|
use meilisearch_types::milli::index::IndexEmbeddingConfig;
|
||||||
use meilisearch_types::milli::update::IndexerConfig;
|
use meilisearch_types::milli::update::IndexerConfig;
|
||||||
use meilisearch_types::milli::vector::{Embedder, EmbedderOptions, EmbeddingConfigs};
|
use meilisearch_types::milli::vector::{Embedder, EmbedderOptions, EmbeddingConfigs};
|
||||||
@ -151,6 +151,9 @@ pub struct IndexScheduler {
|
|||||||
/// In charge of fetching and setting the status of experimental features.
|
/// In charge of fetching and setting the status of experimental features.
|
||||||
features: features::FeatureData,
|
features: features::FeatureData,
|
||||||
|
|
||||||
|
/// Stores the custom prompts for the chat
|
||||||
|
chat_prompts: Database<Str, Str>,
|
||||||
|
|
||||||
/// Everything related to the processing of the tasks
|
/// Everything related to the processing of the tasks
|
||||||
pub scheduler: scheduler::Scheduler,
|
pub scheduler: scheduler::Scheduler,
|
||||||
|
|
||||||
@ -209,11 +212,16 @@ impl IndexScheduler {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
run_loop_iteration: self.run_loop_iteration.clone(),
|
run_loop_iteration: self.run_loop_iteration.clone(),
|
||||||
features: self.features.clone(),
|
features: self.features.clone(),
|
||||||
|
chat_prompts: self.chat_prompts.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const fn nb_db() -> u32 {
|
pub(crate) const fn nb_db() -> u32 {
|
||||||
Versioning::nb_db() + Queue::nb_db() + IndexMapper::nb_db() + features::FeatureData::nb_db()
|
Versioning::nb_db()
|
||||||
|
+ Queue::nb_db()
|
||||||
|
+ IndexMapper::nb_db()
|
||||||
|
+ features::FeatureData::nb_db()
|
||||||
|
+ 1 // chat-prompts
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an index scheduler and start its run loop.
|
/// Create an index scheduler and start its run loop.
|
||||||
@ -267,6 +275,7 @@ impl IndexScheduler {
|
|||||||
let features = features::FeatureData::new(&env, &mut wtxn, options.instance_features)?;
|
let features = features::FeatureData::new(&env, &mut wtxn, options.instance_features)?;
|
||||||
let queue = Queue::new(&env, &mut wtxn, &options)?;
|
let queue = Queue::new(&env, &mut wtxn, &options)?;
|
||||||
let index_mapper = IndexMapper::new(&env, &mut wtxn, &options, budget)?;
|
let index_mapper = IndexMapper::new(&env, &mut wtxn, &options, budget)?;
|
||||||
|
let chat_prompts = env.create_database(&mut wtxn, Some("chat-prompts"))?;
|
||||||
wtxn.commit()?;
|
wtxn.commit()?;
|
||||||
|
|
||||||
// allow unreachable_code to get rids of the warning in the case of a test build.
|
// allow unreachable_code to get rids of the warning in the case of a test build.
|
||||||
@ -290,6 +299,7 @@ impl IndexScheduler {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
run_loop_iteration: Arc::new(RwLock::new(0)),
|
run_loop_iteration: Arc::new(RwLock::new(0)),
|
||||||
features,
|
features,
|
||||||
|
chat_prompts,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.run();
|
this.run();
|
||||||
@ -857,6 +867,10 @@ impl IndexScheduler {
|
|||||||
.collect();
|
.collect();
|
||||||
res.map(EmbeddingConfigs::new)
|
res.map(EmbeddingConfigs::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn chat_prompts<'t>(&self, rtxn: &'t RoTxn, name: &str) -> heed::Result<Option<&'t str>> {
|
||||||
|
self.chat_prompts.get(rtxn, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The outcome of calling the [`IndexScheduler::tick`] function.
|
/// The outcome of calling the [`IndexScheduler::tick`] function.
|
||||||
|
@ -17,7 +17,7 @@ use meilisearch_types::milli::index::IndexEmbeddingConfig;
|
|||||||
use meilisearch_types::milli::prompt::PromptData;
|
use meilisearch_types::milli::prompt::PromptData;
|
||||||
use meilisearch_types::milli::vector::EmbeddingConfig;
|
use meilisearch_types::milli::vector::EmbeddingConfig;
|
||||||
use meilisearch_types::{Document, Index};
|
use meilisearch_types::{Document, Index};
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::extractors::authentication::policies::ActionPolicy;
|
use crate::extractors::authentication::policies::ActionPolicy;
|
||||||
@ -68,6 +68,24 @@ async fn chat(
|
|||||||
"Meilisearch /chat only support one completion at a time (n = 1, n = null)"
|
"Meilisearch /chat only support one completion at a time (n = 1, n = null)"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let rtxn = index_scheduler.read_txn().unwrap();
|
||||||
|
let search_in_index_description = index_scheduler
|
||||||
|
.chat_prompts(&rtxn, "searchInIndex-description")
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(DEFAULT_SEARCH_IN_INDEX_TOOL_DESCRIPTION)
|
||||||
|
.to_string();
|
||||||
|
let search_in_index_q_param_description = index_scheduler
|
||||||
|
.chat_prompts(&rtxn, "searchInIndex-q-param-description")
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(DEFAULT_SEARCH_IN_INDEX_Q_PARAMETER_TOOL_DESCRIPTION)
|
||||||
|
.to_string();
|
||||||
|
let search_in_index_index_description = index_scheduler
|
||||||
|
.chat_prompts(&rtxn, "searchInIndex-index-param-description")
|
||||||
|
.unwrap()
|
||||||
|
.unwrap_or(DEFAULT_SEARCH_IN_INDEX_INDEX_PARAMETER_TOOL_DESCRIPTION)
|
||||||
|
.to_string();
|
||||||
|
drop(rtxn);
|
||||||
|
|
||||||
let mut response;
|
let mut response;
|
||||||
loop {
|
loop {
|
||||||
let mut tools = chat_completion.tools.get_or_insert_default();
|
let mut tools = chat_completion.tools.get_or_insert_default();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user