mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 22:13:47 +00:00
added possibility to add tokenizer via plugin and refactored earlier changes
This commit is contained in:
1 parent
95fb213069
commit
aa554d4a53
15 files changed
+306
-41
No files matched your search
@@ -29,12 +29,11 @@ public sealed partial class RustService
|
||||
return await result.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions);
|
||||
}
|
||||
|
||||
public async Task<TokenizerResponse> StoreTokenizer(string modelId, string previousmodelId, string filePath)
|
||||
public async Task<TokenizerResponse> StoreTokenizer(string modelId, string filePath)
|
||||
{
|
||||
this.logger!.LogInformation($"Storing tokenizer for model '{modelId}' with previous model '{previousmodelId}' from file '{filePath}'");
|
||||
this.logger!.LogInformation($"Storing tokenizer for model '{modelId}' from file '{filePath}'");
|
||||
var result = await this.http.PostAsJsonAsync("/tokenizer/store", new {
|
||||
model_id = modelId,
|
||||
previous_model_id = previousmodelId,
|
||||
file_path = filePath,
|
||||
}, this.jsonRustSerializerOptions);
|
||||
|
||||
@@ -50,6 +49,26 @@ public sealed partial class RustService
|
||||
|
||||
return await result.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions);
|
||||
}
|
||||
|
||||
public async Task<TokenizerResponse> DeleteTokenizer(string modelId)
|
||||
{
|
||||
this.logger!.LogInformation($"Deleting tokenizer for model '{modelId}'");
|
||||
var result = await this.http.PostAsJsonAsync("/tokenizer/delete", new {
|
||||
model_id = modelId,
|
||||
}, this.jsonRustSerializerOptions);
|
||||
|
||||
if (!result.IsSuccessStatusCode)
|
||||
{
|
||||
this.logger!.LogError($"Failed to delete the tokenizer '{result.StatusCode}'");
|
||||
return new TokenizerResponse{
|
||||
Success = false,
|
||||
Message = "An error occured while sending the tokenizer delete request to the Rust framework: "+result.StatusCode,
|
||||
TokenCount = 0
|
||||
};
|
||||
}
|
||||
|
||||
return await result.Content.ReadFromJsonAsync<TokenizerResponse>(this.jsonRustSerializerOptions);
|
||||
}
|
||||
|
||||
public async Task<TokenizerResponse?> GetTokenCount(string text)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AIStudio.Tools.Services;
|
||||
|
||||
public static class TokenizerModelId
|
||||
{
|
||||
public static string ForProvider(Settings.Provider provider) => ForProviderId(provider.Id);
|
||||
|
||||
public static string ForProviderId(string guid) => "chat_" + NormalizeGuid(guid);
|
||||
|
||||
public static string ForEmbeddingProvider(Settings.EmbeddingProvider provider) => ForEmbeddingProviderId(provider.Id);
|
||||
|
||||
public static string ForEmbeddingProviderId(string guid) => "embedding_" + NormalizeGuid(guid);
|
||||
|
||||
private static string NormalizeGuid(string guid)
|
||||
{
|
||||
if (Guid.TryParse(guid, out var parsedGuid))
|
||||
return parsedGuid.ToString("D");
|
||||
|
||||
return guid.Trim();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user