mirror of
https://github.com/SilasMarvin/lsp-ai.git
synced 2025-12-24 01:44:23 +01:00
33 lines
1.0 KiB
Rust
33 lines
1.0 KiB
Rust
use crate::{
|
|
configuration::{Configuration, ValidTransformerBackend},
|
|
worker::{
|
|
DoCompletionResponse, DoGenerateResponse, DoGenerateStreamResponse, GenerateRequest,
|
|
GenerateStreamRequest,
|
|
},
|
|
};
|
|
|
|
pub mod llama_cpp;
|
|
|
|
pub trait TransformerBackend {
|
|
fn init(&self) -> anyhow::Result<()>;
|
|
fn do_completion(&self, prompt: &str) -> anyhow::Result<DoCompletionResponse>;
|
|
fn do_generate(&self, prompt: &str) -> anyhow::Result<DoGenerateResponse>;
|
|
fn do_generate_stream(
|
|
&self,
|
|
request: &GenerateStreamRequest,
|
|
) -> anyhow::Result<DoGenerateStreamResponse>;
|
|
}
|
|
|
|
impl TryFrom<Configuration> for Box<dyn TransformerBackend + Send> {
|
|
type Error = anyhow::Error;
|
|
|
|
fn try_from(configuration: Configuration) -> Result<Self, Self::Error> {
|
|
match configuration.get_transformer_backend()? {
|
|
ValidTransformerBackend::LlamaCPP => {
|
|
Ok(Box::new(llama_cpp::LlamaCPP::new(configuration)))
|
|
}
|
|
_ => unimplemented!(),
|
|
}
|
|
}
|
|
}
|