mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 21:43:45 +03:00
fixed truncation error in fake language model
This commit is contained in:
parent
3447a9478c
commit
ca82ec8e8e
@ -1,6 +1,6 @@
|
||||
use gpui::AppContext;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ProviderCredential {
|
||||
Credentials { api_key: String },
|
||||
NoCredentials,
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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(_) => {
|
||||
|
Loading…
Reference in New Issue
Block a user