Skip to content

Commit

Permalink
Merge pull request #66 from SilasMarvin/release/v0.6.2
Browse files Browse the repository at this point in the history
Release/v0.6.2
  • Loading branch information
SilasMarvin committed Aug 27, 2024
2 parents 470912d + f186ddc commit bf4309a
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 120 deletions.
2 changes: 1 addition & 1 deletion crates/lsp-ai/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lsp-ai"
version = "0.6.1"
version = "0.6.2"

description.workspace = true
repository.workspace = true
Expand Down
82 changes: 39 additions & 43 deletions crates/lsp-ai/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const fn true_default() -> bool {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PostProcess {
pub extractor: Option<String>,
pub(crate) struct PostProcess {
pub(crate) extractor: Option<String>,
#[serde(default = "true_default")]
pub remove_duplicate_start: bool,
pub(crate) remove_duplicate_start: bool,
#[serde(default = "true_default")]
pub remove_duplicate_end: bool,
pub(crate) remove_duplicate_end: bool,
}

impl Default for PostProcess {
Expand All @@ -34,7 +34,7 @@ impl Default for PostProcess {

#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type")]
pub enum ValidSplitter {
pub(crate) enum ValidSplitter {
#[serde(rename = "tree_sitter")]
TreeSitter(TreeSitter),
#[serde(rename = "text_splitter")]
Expand All @@ -56,11 +56,11 @@ const fn chunk_overlap_default() -> usize {
}

#[derive(Debug, Clone, Deserialize)]
pub struct TreeSitter {
pub(crate) struct TreeSitter {
#[serde(default = "chunk_size_default")]
pub chunk_size: usize,
pub(crate) chunk_size: usize,
#[serde(default = "chunk_overlap_default")]
pub chunk_overlap: usize,
pub(crate) chunk_overlap: usize,
}

impl Default for TreeSitter {
Expand All @@ -73,39 +73,39 @@ impl Default for TreeSitter {
}

#[derive(Debug, Clone, Deserialize)]
pub struct TextSplitter {
pub(crate) struct TextSplitter {
#[serde(default = "chunk_size_default")]
pub chunk_size: usize,
pub(crate) chunk_size: usize,
}

#[derive(Debug, Clone, Deserialize, Default)]
pub struct EmbeddingPrefix {
pub(crate) struct EmbeddingPrefix {
#[serde(default)]
pub storage: String,
pub(crate) storage: String,
#[serde(default)]
pub retrieval: String,
pub(crate) retrieval: String,
}

#[derive(Debug, Clone, Deserialize)]
pub struct OllamaEmbeddingModel {
pub(crate) struct OllamaEmbeddingModel {
// The generate endpoint, default: 'http://localhost:11434/api/embeddings'
pub endpoint: Option<String>,
pub(crate) endpoint: Option<String>,
// The model name
pub model: String,
pub(crate) model: String,
// The prefix to apply to the embeddings
#[serde(default)]
pub prefix: EmbeddingPrefix,
pub(crate) prefix: EmbeddingPrefix,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type")]
pub enum ValidEmbeddingModel {
pub(crate) enum ValidEmbeddingModel {
#[serde(rename = "ollama")]
Ollama(OllamaEmbeddingModel),
}

#[derive(Debug, Clone, Copy, Deserialize)]
pub enum VectorDataType {
pub(crate) enum VectorDataType {
#[serde(rename = "f32")]
F32,
#[serde(rename = "binary")]
Expand All @@ -114,11 +114,11 @@ pub enum VectorDataType {

#[derive(Debug, Clone, Deserialize)]
pub(crate) struct VectorStore {
pub crawl: Option<Crawl>,
pub(crate) crawl: Option<Crawl>,
#[serde(default)]
pub splitter: ValidSplitter,
pub embedding_model: ValidEmbeddingModel,
pub data_type: VectorDataType,
pub(crate) splitter: ValidSplitter,
pub(crate) embedding_model: ValidEmbeddingModel,
pub(crate) data_type: VectorDataType,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -265,20 +265,20 @@ const fn n_ctx_default() -> u32 {
#[cfg(feature = "llama_cpp")]
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct LLaMACPP {
pub(crate) struct LLaMACPP {
// Which model to use
pub repository: Option<String>,
pub name: Option<String>,
pub file_path: Option<String>,
pub(crate) repository: Option<String>,
pub(crate) name: Option<String>,
pub(crate) file_path: Option<String>,
// The layers to put on the GPU
#[serde(default = "n_gpu_layers_default")]
pub n_gpu_layers: u32,
pub(crate) n_gpu_layers: u32,
// The context size
#[serde(default = "n_ctx_default")]
pub n_ctx: u32,
pub(crate) n_ctx: u32,
// The maximum requests per second
#[serde(default = "max_requests_per_second_default")]
pub max_requests_per_second: f32,
pub(crate) max_requests_per_second: f32,
}

#[derive(Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -349,7 +349,7 @@ pub(crate) struct Completion {
}

#[derive(Clone, Debug, Deserialize)]
pub struct Chat {
pub(crate) struct Chat {
// The trigger text
pub(crate) trigger: String,
// The name to display in the editor
Expand All @@ -362,7 +362,7 @@ pub struct Chat {
}

#[derive(Clone, Debug, Deserialize)]
pub struct Action {
pub(crate) struct Action {
// The name to display in the editor
pub(crate) action_display_name: String,
// The model key to use
Expand Down Expand Up @@ -395,13 +395,13 @@ pub(crate) struct ValidClientParams {
}

#[derive(Clone, Debug)]
pub struct Config {
pub(crate) struct Config {
pub(crate) config: ValidConfig,
pub(crate) client_params: ValidClientParams,
}

impl Config {
pub fn new(mut args: Value) -> Result<Self> {
pub(crate) fn new(mut args: Value) -> Result<Self> {
// Validate that the models specified are there so we can unwrap
let configuration_args = args
.as_object_mut()
Expand All @@ -422,23 +422,19 @@ impl Config {
// Helpers for the backends ///////////
///////////////////////////////////////

pub fn get_chats(&self) -> &Vec<Chat> {
pub(crate) fn get_chats(&self) -> &Vec<Chat> {
&self.config.chats
}

pub fn get_actions(&self) -> &Vec<Action> {
pub(crate) fn get_actions(&self) -> &Vec<Action> {
&self.config.actions
}

pub fn is_completions_enabled(&self) -> bool {
self.config.completion.is_some()
}

pub fn get_completions_post_process(&self) -> Option<&PostProcess> {
pub(crate) fn get_completions_post_process(&self) -> Option<&PostProcess> {
self.config.completion.as_ref().map(|x| &x.post_process)
}

pub fn get_completion_transformer_max_requests_per_second(&self) -> anyhow::Result<f32> {
pub(crate) fn get_completion_transformer_max_requests_per_second(&self) -> anyhow::Result<f32> {
match &self
.config
.models
Expand Down Expand Up @@ -470,7 +466,7 @@ impl Config {
// For teesting use only
#[cfg(test)]
impl Config {
pub fn default_with_file_store_without_models() -> Self {
pub(crate) fn default_with_file_store_without_models() -> Self {
Self {
config: ValidConfig {
memory: ValidMemoryBackend::FileStore(FileStore { crawl: None }),
Expand Down
2 changes: 1 addition & 1 deletion crates/lsp-ai/src/crawl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Crawl {
}

#[instrument(skip(self, f))]
pub fn maybe_do_crawl(
pub(crate) fn maybe_do_crawl(
&mut self,
triggered_file: Option<String>,
mut f: impl FnMut(&config::Crawl, &str) -> anyhow::Result<bool>,
Expand Down
6 changes: 3 additions & 3 deletions crates/lsp-ai/src/custom_requests/generation_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pub(crate) enum GenerationStream {}

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GenerationStreamParams {
pub partial_result_token: ProgressToken,
pub(crate) struct GenerationStreamParams {
pub(crate) partial_result_token: ProgressToken,

// This field was "mixed-in" from TextDocumentPositionParams
#[serde(flatten)]
pub text_document_position: TextDocumentPositionParams,
pub(crate) text_document_position: TextDocumentPositionParams,
}

#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
Expand Down
6 changes: 3 additions & 3 deletions crates/lsp-ai/src/embedding_models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::config::ValidEmbeddingModel;

mod ollama;

pub fn normalize(mut vector: Vec<f32>) -> Vec<f32> {
fn normalize(mut vector: Vec<f32>) -> Vec<f32> {
let magnitude = (vector.iter().map(|&x| x * x).sum::<f32>()).sqrt();

if magnitude != 0.0 {
Expand All @@ -15,13 +15,13 @@ pub fn normalize(mut vector: Vec<f32>) -> Vec<f32> {
}

#[derive(Clone, Copy)]
pub enum EmbeddingPurpose {
pub(crate) enum EmbeddingPurpose {
Storage,
Retrieval,
}

#[async_trait::async_trait]
pub trait EmbeddingModel {
pub(crate) trait EmbeddingModel {
async fn embed(
&self,
batch: Vec<&str>,
Expand Down
10 changes: 5 additions & 5 deletions crates/lsp-ai/src/embedding_models/ollama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ use crate::config;
use super::{normalize, EmbeddingModel, EmbeddingPurpose};

#[derive(Deserialize)]
pub struct Embed {
pub(crate) struct Embed {
embedding: Vec<f32>,
}

#[derive(Deserialize)]
pub struct EmbedError {
pub(crate) struct EmbedError {
error: Value,
}

#[derive(Deserialize)]
#[serde(untagged)]
pub enum EmbedResponse {
pub(crate) enum EmbedResponse {
Success(Embed),
Error(EmbedError),
Other(HashMap<String, Value>),
}

pub struct Ollama {
pub(crate) struct Ollama {
config: config::OllamaEmbeddingModel,
}

impl Ollama {
pub fn new(config: config::OllamaEmbeddingModel) -> Self {
pub(crate) fn new(config: config::OllamaEmbeddingModel) -> Self {
Self { config }
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/lsp-ai/src/memory_backends/file_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl AdditionalFileStoreParams {
}

#[derive(Clone)]
pub struct File {
pub(crate) struct File {
rope: Rope,
tree: Option<Tree>,
}
Expand All @@ -38,11 +38,11 @@ impl File {
Self { rope, tree }
}

pub fn rope(&self) -> &Rope {
pub(crate) fn rope(&self) -> &Rope {
&self.rope
}

pub fn tree(&self) -> Option<&Tree> {
pub(crate) fn tree(&self) -> Option<&Tree> {
self.tree.as_ref()
}
}
Expand Down Expand Up @@ -278,15 +278,15 @@ impl FileStore {
})
}

pub fn file_map(&self) -> &RwLock<HashMap<String, File>> {
pub(crate) fn file_map(&self) -> &RwLock<HashMap<String, File>> {
&self.file_map
}

pub fn contains_file(&self, uri: &str) -> bool {
pub(crate) fn contains_file(&self, uri: &str) -> bool {
self.file_map.read().contains_key(uri)
}

pub fn position_to_byte(&self, position: &TextDocumentPositionParams) -> anyhow::Result<usize> {
pub(crate) fn position_to_byte(&self, position: &TextDocumentPositionParams) -> anyhow::Result<usize> {
let file_map = self.file_map.read();
let uri = position.text_document.uri.to_string();
let file = file_map
Expand Down Expand Up @@ -494,7 +494,7 @@ impl MemoryBackend for FileStore {
// For testing use only
#[cfg(test)]
impl FileStore {
pub fn default_with_filler_file() -> anyhow::Result<Self> {
pub(crate) fn default_with_filler_file() -> anyhow::Result<Self> {
let config = Config::default_with_file_store_without_models();
let file_store_config = if let config::ValidMemoryBackend::FileStore(file_store_config) =
config.config.memory.clone()
Expand Down
Loading

0 comments on commit bf4309a

Please sign in to comment.