mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-05-20 03:12:15 +00:00
cleanup to ensure uniform style of code
This commit is contained in:
parent
41573406d5
commit
4a8ab90173
@ -995,7 +995,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tokenizerResponse = await this.RustService.EnsureTokenizer(this.Provider);
|
var tokenizerResponse = await this.RustService.EnsureTokenizer(this.Provider.InstanceName, this.Provider.TokenizerPath);
|
||||||
if (tokenizerResponse is null)
|
if (tokenizerResponse is null)
|
||||||
return;
|
return;
|
||||||
if (!tokenizerResponse.Value.Success)
|
if (!tokenizerResponse.Value.Success)
|
||||||
|
|||||||
@ -157,7 +157,7 @@ public partial class SettingsPanelEmbeddings : SettingsPanelProviderBase
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var embeddingProvider = provider.CreateProvider();
|
var embeddingProvider = provider.CreateProvider();
|
||||||
var embeddings = await embeddingProvider.EmbedTextAsync(provider.Model, this.SettingsManager, default, new List<string> { inputText });
|
var embeddings = await embeddingProvider.EmbedTextAsync(provider.Model, this.SettingsManager, CancellationToken.None, inputText);
|
||||||
|
|
||||||
if (embeddings.Count == 0)
|
if (embeddings.Count == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public sealed partial class RustService
|
|||||||
|
|
||||||
public async Task<TokenizerResponse> StoreTokenizer(string modelId, string previousmodelId, string filePath)
|
public async Task<TokenizerResponse> StoreTokenizer(string modelId, string previousmodelId, string filePath)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Storing tokenizer for model '{modelId}' with previous model '{previousmodelId}' from file '{filePath}'");
|
this.logger!.LogInformation($"Storing tokenizer for model '{modelId}' with previous model '{previousmodelId}' from file '{filePath}'");
|
||||||
var result = await this.http.PostAsJsonAsync("/tokenizer/store", new {
|
var result = await this.http.PostAsJsonAsync("/tokenizer/store", new {
|
||||||
model_id = modelId,
|
model_id = modelId,
|
||||||
previous_model_id = previousmodelId,
|
previous_model_id = previousmodelId,
|
||||||
@ -53,28 +53,26 @@ public sealed partial class RustService
|
|||||||
|
|
||||||
public async Task<TokenizerResponse?> GetTokenCount(string text)
|
public async Task<TokenizerResponse?> GetTokenCount(string text)
|
||||||
{
|
{
|
||||||
try
|
var result = await this.http.PostAsJsonAsync("/tokenizer/count", new {
|
||||||
|
text = text,
|
||||||
|
}, this.jsonRustSerializerOptions);
|
||||||
|
|
||||||
|
if (!result.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
this.logger!.LogError($"Failed to get the token count '{result.StatusCode}'");
|
||||||
var payload = new { text };
|
return new TokenizerResponse{
|
||||||
var response = await this.http.PostAsJsonAsync("/tokenizer/count", payload, this.jsonRustSerializerOptions, cts.Token);
|
Success = false,
|
||||||
response.EnsureSuccessStatusCode();
|
Message = "Error while getting token count from Rust service: "+result.StatusCode,
|
||||||
return await response.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions, cancellationToken: cts.Token);
|
TokenCount = 0
|
||||||
}
|
};
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
if(this.logger is not null)
|
|
||||||
this.logger.LogError(e, "Error while getting token count from Rust service.");
|
|
||||||
else
|
|
||||||
Console.WriteLine($"Error while getting token count from Rust service: '{e}'.");
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return await result.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<TokenizerResponse?> SetTokenizer(string providerName, string path)
|
public async Task<TokenizerResponse?> SetTokenizer(string providerName, string path)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Setting a new tokenizer for '{providerName}'");
|
this.logger!.LogInformation($"Setting a new tokenizer for '{providerName}'");
|
||||||
var result = await this.http.PostAsJsonAsync("/tokenizer/set", new {
|
var result = await this.http.PostAsJsonAsync("/tokenizer/set", new {
|
||||||
file_path = path,
|
file_path = path,
|
||||||
}, this.jsonRustSerializerOptions);
|
}, this.jsonRustSerializerOptions);
|
||||||
@ -92,17 +90,7 @@ public sealed partial class RustService
|
|||||||
return await result.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions);
|
return await result.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TokenizerResponse?> EnsureTokenizer(Settings.Provider provider)
|
public async Task<TokenizerResponse?> EnsureTokenizer(string providerName, string path)
|
||||||
{
|
|
||||||
return this.EnsureTokenizer(provider.InstanceName, provider.TokenizerPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<TokenizerResponse?> EnsureTokenizer(IProvider provider)
|
|
||||||
{
|
|
||||||
return this.EnsureTokenizer(provider.InstanceName, provider.TokenizerPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<TokenizerResponse?> EnsureTokenizer(string providerName, string path)
|
|
||||||
{
|
{
|
||||||
await this.tokenizerLock.WaitAsync();
|
await this.tokenizerLock.WaitAsync();
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user