-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/multi_file_context
- Loading branch information
Showing
21 changed files
with
687 additions
and
771 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,14 @@ | ||
[package] | ||
name = "custom-types" | ||
version = "0.1.0" | ||
edition.workspace = true | ||
license.workspace = true | ||
authors.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
lsp-types = "0.94" | ||
serde = "1" | ||
serde_json = "1" | ||
uuid = "1" |
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,2 @@ | ||
pub mod llm_ls; | ||
pub mod request; |
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,156 @@ | ||
use std::{fmt::Display, path::PathBuf}; | ||
|
||
use lsp_types::TextDocumentPositionParams; | ||
use serde::{Deserialize, Deserializer, Serialize}; | ||
use serde_json::{Map, Value}; | ||
use uuid::Uuid; | ||
|
||
const HF_INFERENCE_API_HOSTNAME: &str = "api-inference.huggingface.co"; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct AcceptCompletionParams { | ||
pub request_id: Uuid, | ||
pub accepted_completion: u32, | ||
pub shown_completions: Vec<u32>, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct RejectCompletionParams { | ||
pub request_id: Uuid, | ||
pub shown_completions: Vec<u32>, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum Ide { | ||
Neovim, | ||
VSCode, | ||
JetBrains, | ||
Emacs, | ||
Jupyter, | ||
Sublime, | ||
VisualStudio, | ||
#[default] | ||
Unknown, | ||
} | ||
|
||
impl Display for Ide { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
self.serialize(f) | ||
} | ||
} | ||
|
||
fn parse_ide<'de, D>(d: D) -> std::result::Result<Ide, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
Option::deserialize(d).map(|b| b.unwrap_or_default()) | ||
} | ||
|
||
fn parse_url<'de, D>(d: D) -> std::result::Result<String, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
Option::deserialize(d).map(|b| b.unwrap_or_else(hf_default_url)) | ||
} | ||
|
||
fn hf_default_url() -> String { | ||
format!("https://{HF_INFERENCE_API_HOSTNAME}") | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "lowercase", tag = "backend")] | ||
pub enum Backend { | ||
HuggingFace { | ||
#[serde(default = "hf_default_url", deserialize_with = "parse_url")] | ||
url: String, | ||
}, | ||
// TODO: | ||
// LlamaCpp { | ||
// url: String, | ||
// }, | ||
Ollama { | ||
url: String, | ||
}, | ||
OpenAi { | ||
url: String, | ||
}, | ||
Tgi { | ||
url: String, | ||
}, | ||
} | ||
|
||
impl Default for Backend { | ||
fn default() -> Self { | ||
Self::HuggingFace { | ||
url: hf_default_url(), | ||
} | ||
} | ||
} | ||
|
||
impl Backend { | ||
pub fn is_using_inference_api(&self) -> bool { | ||
match self { | ||
Self::HuggingFace { url } => url.contains(HF_INFERENCE_API_HOSTNAME), | ||
_ => false, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct FimParams { | ||
pub enabled: bool, | ||
pub prefix: String, | ||
pub middle: String, | ||
pub suffix: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[serde(untagged)] | ||
pub enum TokenizerConfig { | ||
Local { | ||
path: PathBuf, | ||
}, | ||
HuggingFace { | ||
repository: String, | ||
api_token: Option<String>, | ||
}, | ||
Download { | ||
url: String, | ||
to: PathBuf, | ||
}, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct GetCompletionsParams { | ||
#[serde(flatten)] | ||
pub text_document_position: TextDocumentPositionParams, | ||
#[serde(default)] | ||
#[serde(deserialize_with = "parse_ide")] | ||
pub ide: Ide, | ||
pub fim: FimParams, | ||
pub api_token: Option<String>, | ||
pub model: String, | ||
#[serde(flatten)] | ||
pub backend: Backend, | ||
pub tokens_to_clear: Vec<String>, | ||
pub tokenizer_config: Option<TokenizerConfig>, | ||
pub context_window: usize, | ||
pub tls_skip_verify_insecure: bool, | ||
#[serde(default)] | ||
pub request_body: Map<String, Value>, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Completion { | ||
pub generated_text: String, | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct GetCompletionsResult { | ||
pub request_id: Uuid, | ||
pub completions: Vec<Completion>, | ||
} |
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,32 @@ | ||
use lsp_types::request::Request; | ||
|
||
use crate::llm_ls::{ | ||
AcceptCompletionParams, GetCompletionsParams, GetCompletionsResult, RejectCompletionParams, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub enum GetCompletions {} | ||
|
||
impl Request for GetCompletions { | ||
type Params = GetCompletionsParams; | ||
type Result = GetCompletionsResult; | ||
const METHOD: &'static str = "llm-ls/getCompletions"; | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum AcceptCompletion {} | ||
|
||
impl Request for AcceptCompletion { | ||
type Params = AcceptCompletionParams; | ||
type Result = (); | ||
const METHOD: &'static str = "llm-ls/acceptCompletion"; | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum RejectCompletion {} | ||
|
||
impl Request for RejectCompletion { | ||
type Params = RejectCompletionParams; | ||
type Result = (); | ||
const METHOD: &'static str = "llm-ls/rejectCompletion"; | ||
} |
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
Oops, something went wrong.