fixed truncation error in fake language model

This commit is contained in:
KCaverly 2023-10-26 14:05:55 +02:00
parent 3447a9478c
commit ca82ec8e8e
4 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,6 @@
use gpui::AppContext; use gpui::AppContext;
#[derive(Clone)] #[derive(Clone, Debug)]
pub enum ProviderCredential { pub enum ProviderCredential {
Credentials { api_key: String }, Credentials { api_key: String },
NoCredentials, NoCredentials,

View File

@ -29,6 +29,10 @@ impl LanguageModel for FakeLanguageModel {
length: usize, length: usize,
direction: TruncationDirection, direction: TruncationDirection,
) -> anyhow::Result<String> { ) -> anyhow::Result<String> {
if length > self.count_tokens(content)? {
return anyhow::Ok(content.to_string());
}
anyhow::Ok(match direction { anyhow::Ok(match direction {
TruncationDirection::End => content.chars().collect::<Vec<char>>()[..length] TruncationDirection::End => content.chars().collect::<Vec<char>>()[..length]
.into_iter() .into_iter()

View File

@ -69,7 +69,7 @@ impl EmbeddingQueue {
} }
pub fn set_credential(&mut self, credential: ProviderCredential) { pub fn set_credential(&mut self, credential: ProviderCredential) {
self.provider_credential = credential self.provider_credential = credential;
} }
pub fn push(&mut self, file: FileToEmbed) { pub fn push(&mut self, file: FileToEmbed) {

View File

@ -291,7 +291,6 @@ impl SemanticIndex {
} }
self.embedding_queue.lock().set_credential(credential); self.embedding_queue.lock().set_credential(credential);
self.is_authenticated() self.is_authenticated()
} }
@ -299,6 +298,7 @@ impl SemanticIndex {
let credential = &self.provider_credential; let credential = &self.provider_credential;
match credential { match credential {
&ProviderCredential::Credentials { .. } => true, &ProviderCredential::Credentials { .. } => true,
&ProviderCredential::NotNeeded => true,
_ => false, _ => false,
} }
} }
@ -1020,11 +1020,14 @@ impl SemanticIndex {
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
if !self.is_authenticated() { if !self.is_authenticated() {
println!("Authenticating");
if !self.authenticate(cx) { if !self.authenticate(cx) {
return Task::ready(Err(anyhow!("user is not authenticated"))); return Task::ready(Err(anyhow!("user is not authenticated")));
} }
} }
println!("SHOULD NOW BE AUTHENTICATED");
if !self.projects.contains_key(&project.downgrade()) { if !self.projects.contains_key(&project.downgrade()) {
let subscription = cx.subscribe(&project, |this, project, event, cx| match event { let subscription = cx.subscribe(&project, |this, project, event, cx| match event {
project::Event::WorktreeAdded | project::Event::WorktreeRemoved(_) => { project::Event::WorktreeAdded | project::Event::WorktreeRemoved(_) => {