Merge pull request #634 from iceljc/features/add-knowledge-docs

use binary data
This commit is contained in:
iceljc 2024-09-11 20:06:29 -05:00 committed by GitHub
commit 793905436b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 10 deletions

View file

@ -63,7 +63,7 @@ public interface IFileStorageService
#endregion
#region Knowledge
bool SaveKnowledgeBaseFile(string collectionName, string vectorStoreProvider, string fileId, string fileName, Stream stream);
bool SaveKnowledgeBaseFile(string collectionName, string vectorStoreProvider, string fileId, string fileName, BinaryData fileData);
/// <summary>
/// Delete files in a knowledge collection. If fileId is null, remove all files in the collection.

View file

@ -5,7 +5,7 @@ namespace BotSharp.Core.Files.Services;
public partial class LocalFileStorageService
{
public bool SaveKnowledgeBaseFile(string collectionName, string vectorStoreProvider, string fileId, string fileName, Stream stream)
public bool SaveKnowledgeBaseFile(string collectionName, string vectorStoreProvider, string fileId, string fileName, BinaryData fileData)
{
if (string.IsNullOrWhiteSpace(collectionName)
|| string.IsNullOrWhiteSpace(vectorStoreProvider)
@ -26,9 +26,9 @@ public partial class LocalFileStorageService
var filePath = Path.Combine(dir, fileName);
using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
stream.CopyTo(fs);
using var ds = fileData.ToStream();
ds.CopyTo(fs);
fs.Flush();
fs.Close();
return true;
}
catch (Exception ex)

View file

@ -208,11 +208,8 @@ public partial class KnowledgeService
private bool SaveDocument(string collectionName, string vectorStoreProvider, string fileId, string fileName, byte[] bytes)
{
var fileStoreage = _services.GetRequiredService<IFileStorageService>();
using var stream = new MemoryStream(bytes);
stream.Position = 0;
var saved = fileStoreage.SaveKnowledgeBaseFile(collectionName.CleanStr(), vectorStoreProvider.CleanStr(), fileId, fileName, stream);
stream.Close();
var data = BinaryData.FromBytes(bytes);
var saved = fileStoreage.SaveKnowledgeBaseFile(collectionName.CleanStr(), vectorStoreProvider.CleanStr(), fileId, fileName, data);
return saved;
}

View file

@ -4,7 +4,7 @@ namespace BotSharp.Plugin.TencentCos.Services;
public partial class TencentCosService
{
public bool SaveKnowledgeBaseFile(string collectionName, string vectorStoreProvider, string fileId, string fileName, Stream stream)
public bool SaveKnowledgeBaseFile(string collectionName, string vectorStoreProvider, string fileId, string fileName, BinaryData fileData)
{
throw new NotImplementedException();
}