Skip to content

Commit 6c9ba17

Browse files
authored
Merge pull request #645 from iceljc/features/add-knowledge-docs
add web url in file meta
2 parents cd96a4d + 87b36f8 commit 6c9ba17

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeDocMetaData.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class KnowledgeDocMetaData
2323
[JsonPropertyName("vector_data_ids")]
2424
public IEnumerable<string> VectorDataIds { get; set; } = new List<string>();
2525

26+
[JsonPropertyName("web_url")]
27+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
28+
public string? WebUrl { get; set; }
2629

2730
[JsonPropertyName("create_date")]
2831
public DateTime CreateDate { get; set; } = DateTime.UtcNow;

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Document.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,19 @@ public async Task<PagedItems<KnowledgeFileModel>> GetPagedKnowledgeDocuments(str
150150
Size = filter.Size
151151
});
152152

153-
var files = pagedData.Items?.Select(x => new KnowledgeFileModel
153+
var files = pagedData.Items?.Select(x =>
154154
{
155-
FileId = x.FileId,
156-
FileName = x.FileName,
157-
FileExtension = Path.GetExtension(x.FileName),
158-
ContentType = x.ContentType,
159-
FileUrl = fileStorage.GetKnowledgeBaseFileUrl(collectionName, vectorStoreProvider, x.FileId, x.FileName)
155+
var fileUrl = x.ContentType == MediaTypeNames.Text.Html ?
156+
x.WebUrl : fileStorage.GetKnowledgeBaseFileUrl(collectionName, vectorStoreProvider, x.FileId, x.FileName);
157+
158+
return new KnowledgeFileModel
159+
{
160+
FileId = x.FileId,
161+
FileName = x.FileName,
162+
FileExtension = Path.GetExtension(x.FileName),
163+
ContentType = x.ContentType,
164+
FileUrl = fileUrl
165+
};
160166
})?.ToList() ?? new List<KnowledgeFileModel>();
161167

162168
return new PagedItems<KnowledgeFileModel>

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/KnowledgeCollectionFileMetaDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class KnowledgeCollectionFileMetaDocument : MongoBase
99
public string ContentType { get; set; }
1010
public string VectorStoreProvider { get; set; }
1111
public IEnumerable<string> VectorDataIds { get; set; } = new List<string>();
12+
public string? WebUrl { get; set; }
1213
public DateTime CreateDate { get; set; }
1314
public string CreateUserId { get; set; }
1415
}

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public bool SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData)
135135
ContentType = metaData.ContentType,
136136
VectorStoreProvider = metaData.VectorStoreProvider,
137137
VectorDataIds = metaData.VectorDataIds,
138+
WebUrl = metaData.WebUrl,
138139
CreateDate = metaData.CreateDate,
139140
CreateUserId = metaData.CreateUserId
140141
};
@@ -202,6 +203,7 @@ public PagedItems<KnowledgeDocMetaData> GetKnowledgeBaseFileMeta(string collecti
202203
ContentType = x.ContentType,
203204
VectorStoreProvider = x.VectorStoreProvider,
204205
VectorDataIds = x.VectorDataIds,
206+
WebUrl = x.WebUrl,
205207
CreateDate = x.CreateDate,
206208
CreateUserId = x.CreateUserId
207209
})?.ToList() ?? new List<KnowledgeDocMetaData>();

0 commit comments

Comments
 (0)