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;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum ProviderCredential {
Credentials { api_key: String },
NoCredentials,

View File

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

View File

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

View File

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