use binary data
This commit is contained in:
parent
057190a245
commit
b8f013aad2
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue