Skip to content

Commit 1942c4a

Browse files
committed
Restructure project files
Add API key to functional tests Update some dependencies
1 parent 6f32d22 commit 1942c4a

File tree

257 files changed

+562
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+562
-378
lines changed

KernelMemory.sln

Lines changed: 73 additions & 61 deletions
Large diffs are not rendered by default.

plugins/dotnet/Microsoft.KernelMemory.Plugin/TypeConverter.cs renamed to clients/dotnet/Plugin/Internals/TypeConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Globalization;
77
using System.Text.Json;
88

9-
namespace Microsoft.KernelMemory.Plugin;
9+
namespace Microsoft.KernelMemory.Plugin.Internals;
1010

1111
[TypeConverter(typeof(TypeConverter))]
1212
public class TagCollectionWrapper : TagCollection

plugins/dotnet/Microsoft.KernelMemory.Plugin/MemoryPlugin.cs renamed to clients/dotnet/Plugin/MemoryPlugin.cs

Lines changed: 108 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Microsoft.Extensions.Logging;
9-
using Microsoft.KernelMemory.Plugin;
9+
using Microsoft.KernelMemory.Plugin.Internals;
1010
using Microsoft.SemanticKernel;
1111

1212
#pragma warning disable IDE0130 // reduce number of "using" statements
@@ -65,10 +65,9 @@ public class MemoryPlugin
6565
public const string MinRelevanceParam = "minRelevance";
6666

6767
/// <summary>
68-
/// Default document ID. When null, a new value is generated every time some information
69-
/// is saved into memory.
68+
/// Name of the input variable used to specify the maximum number of items to return.
7069
/// </summary>
71-
private const string? DefaultDocumentId = null;
70+
public const string LimitParam = "limit";
7271

7372
/// <summary>
7473
/// Default index where to store and retrieve memory from. When null the service
@@ -100,7 +99,7 @@ public class MemoryPlugin
10099
/// <summary>
101100
/// Max time to wait for ingestion completion when <see cref="_waitForIngestionToComplete"/> is set to True.
102101
/// </summary>
103-
private TimeSpan _maxIngestionWait = TimeSpan.FromSeconds(15);
102+
private readonly TimeSpan _maxIngestionWait = TimeSpan.FromSeconds(15);
104103

105104
/// <summary>
106105
/// Client to memory read/write. This is usually an instance of MemoryWebClient
@@ -135,6 +134,7 @@ public MemoryPlugin(
135134
defaultIngestionSteps,
136135
waitForIngestionToComplete)
137136
{
137+
// TODO: add api key header name
138138
}
139139

140140
/// <summary>
@@ -186,7 +186,7 @@ public MemoryPlugin(
186186
/// </summary>
187187
/// <example>
188188
/// SKContext.Variables["input"] = "the capital of France is Paris"
189-
/// {{memory.importText $input }}
189+
/// {{memory.save $input }}
190190
/// </example>
191191
/// <example>
192192
/// SKContext.Variables["input"] = "the capital of France is Paris"
@@ -199,10 +199,9 @@ public MemoryPlugin(
199199
/// {{memory.save $input }}
200200
/// </example>
201201
/// <returns>Document ID</returns>
202-
[SKFunction, Description("Store in memory the information extracted from the given text")]
202+
[SKFunction, Description("Store in memory the given text")]
203203
public async Task<string> SaveAsync(
204-
[Description("The information to save")]
205-
string input,
204+
[Description("The text to save")] string input,
206205
[SKName(DocumentIdParam), Description("The document ID associated with the information to save"), DefaultValue(null)]
207206
string? documentId = null,
208207
[SKName(IndexParam), Description("Memories index associated with the information to save"), DefaultValue(null)]
@@ -214,6 +213,8 @@ public async Task<string> SaveAsync(
214213
ILoggerFactory? loggerFactory = null,
215214
CancellationToken cancellationToken = default)
216215
{
216+
// TODO: check if one has to use "input" or "documentId"
217+
217218
Task<string> Do(CancellationToken token)
218219
{
219220
return this._memory.ImportTextAsync(
@@ -228,16 +229,38 @@ Task<string> Do(CancellationToken token)
228229
if (this._waitForIngestionToComplete)
229230
{
230231
using var cs = new CancellationTokenSource(this._maxIngestionWait);
231-
return await Do(cs.Token).ConfigureAwait(false);
232+
string id = await Do(cs.Token).ConfigureAwait(false);
233+
// TODO CHECK IF DOC HAS BEEN IMPORTED
234+
return id;
232235
}
233236

234237
return await Do(cancellationToken).ConfigureAwait(false);
235238
}
236239

240+
/// <summary>
241+
/// Store a file content in long term memory.
242+
///
243+
/// Usage from prompts: '{{memory.saveFile ...}}'
244+
/// </summary>
245+
/// <example>
246+
/// SKContext.Variables["input"] = "C:\Documents\presentation.pptx"
247+
/// {{memory.saveFile $input }}
248+
/// </example>
249+
/// <example>
250+
/// SKContext.Variables["input"] = "C:\Documents\presentation.pptx"
251+
/// SKContext.Variables[MemoryPlugin.IndexParam] = "work"
252+
/// {{memory.saveFile $input }}
253+
/// </example>
254+
/// <example>
255+
/// SKContext.Variables["input"] = "C:\Documents\presentation.pptx"
256+
/// SKContext.Variables[MemoryPlugin.DocumentIdParam] = "presentation001"
257+
/// {{memory.saveFile $input }}
258+
/// </example>
259+
/// <returns>Document ID</returns>
237260
[SKFunction, Description("Store in memory the information extracted from a file")]
238261
public async Task<string> SaveFileAsync(
239262
[Description("Path of the file to save in memory")]
240-
string input,
263+
string filePath,
241264
[SKName(DocumentIdParam), Description("The document ID associated with the information to save"), DefaultValue(null)]
242265
string? documentId = null,
243266
[SKName(IndexParam), Description("Memories index associated with the information to save"), DefaultValue(null)]
@@ -252,34 +275,75 @@ public async Task<string> SaveFileAsync(
252275
Task<string> Do(CancellationToken token)
253276
{
254277
return this._memory.ImportDocumentAsync(
255-
filePath: input,
278+
filePath: filePath,
256279
documentId: documentId,
257-
index: index ?? this._defaultIndex,
258280
tags: tags ?? this._defaultIngestionTags,
281+
index: index ?? this._defaultIndex,
259282
steps: steps ?? this._defaultIngestionSteps,
260283
cancellationToken: token);
261284
}
262285

263286
if (this._waitForIngestionToComplete)
264287
{
265288
using var cs = new CancellationTokenSource(this._maxIngestionWait);
266-
return await Do(cs.Token).ConfigureAwait(false);
289+
string id = await Do(cs.Token).ConfigureAwait(false);
290+
// TODO CHECK IF DOC HAS BEEN IMPORTED
291+
return id;
267292
}
268293

269294
return await Do(cancellationToken).ConfigureAwait(false);
270295
}
271296

272297
[SKFunction, Description("Store in memory the information extracted from a web page")]
273-
public async Task<string> SaveWebPageAsync()
298+
public async Task<string> SaveWebPageAsync(
299+
[Description("Complete URL of the web page to save")]
300+
string url,
301+
[SKName(DocumentIdParam), Description("The document ID associated with the information to save"), DefaultValue(null)]
302+
string? documentId = null,
303+
[SKName(IndexParam), Description("Memories index associated with the information to save"), DefaultValue(null)]
304+
string? index = null,
305+
[SKName(TagsParam), Description("Memories index associated with the information to save"), DefaultValue(null)]
306+
TagCollectionWrapper? tags = null,
307+
[SKName(StepsParam), Description("Steps to parse the information and store in memory"), DefaultValue(null)]
308+
ListOfStringsWrapper? steps = null,
309+
ILoggerFactory? loggerFactory = null,
310+
CancellationToken cancellationToken = default)
274311
{
275-
await Task.Delay(0).ConfigureAwait(false);
276-
throw new NotImplementedException();
312+
Task<string> Do(CancellationToken token)
313+
{
314+
return this._memory.ImportWebPageAsync(
315+
url: url,
316+
documentId: documentId,
317+
tags: tags ?? this._defaultIngestionTags,
318+
index: index ?? this._defaultIndex,
319+
steps: steps ?? this._defaultIngestionSteps,
320+
cancellationToken: token);
321+
}
322+
323+
if (this._waitForIngestionToComplete)
324+
{
325+
using var cs = new CancellationTokenSource(this._maxIngestionWait);
326+
string id = await Do(cs.Token).ConfigureAwait(false);
327+
// TODO CHECK IF DOC HAS BEEN IMPORTED
328+
return id;
329+
}
330+
331+
return await Do(cancellationToken).ConfigureAwait(false);
277332
}
278333

279334
[SKFunction, Description("Return up to N memories related to the input text")]
280-
public async Task<string> SearchAsync()
335+
public async Task<string> SearchAsync(
336+
[Description("The text to search")] string query,
337+
[SKName(IndexParam), Description("Memories index to search for information"), DefaultValue("")]
338+
string? index = null,
339+
[SKName(MinRelevanceParam), Description("Minimum relevance of the memories to return"), DefaultValue(0d)]
340+
double minRelevance = 0,
341+
[SKName(LimitParam), Description("Maximum number of memories to return"), DefaultValue(0d)]
342+
int limit = 10,
343+
CancellationToken cancellationToken = default)
281344
{
282-
await Task.Delay(0).ConfigureAwait(false);
345+
await Task.Delay(0, cancellationToken).ConfigureAwait(false);
346+
// TODO check the old Semantic Memory
283347
throw new NotImplementedException();
284348
}
285349

@@ -288,43 +352,43 @@ public async Task<string> SearchAsync()
288352
///
289353
/// Usage from prompts: '{{memory.ask ...}}'
290354
/// </summary>
291-
/// <param name="input">The question to answer</param>
292355
/// <returns>The answer returned by the memory.</returns>
293356
[SKFunction, Description("Use long term memory to answer a quesion")]
294357
public async Task<string> AskAsync(
295358
[Description("The question to answer")]
296-
string input,
359+
string question,
297360
[SKName(IndexParam), Description("Memories index to search for answers"), DefaultValue("")]
298361
string? index = null,
299-
[SKName(MinRelevanceParam), Description("Memories index to search for answers"), DefaultValue(0d)]
362+
[SKName(MinRelevanceParam), Description("Minimum relevance of the sources to consider"), DefaultValue(0d)]
300363
double minRelevance = 0,
301364
ILoggerFactory? loggerFactory = null,
302365
CancellationToken cancellationToken = default)
303366
{
304-
Task<MemoryAnswer> Do(CancellationToken token)
305-
{
306-
return this._memory.AskAsync(question: input, cancellationToken: token);
307-
}
308-
309-
MemoryAnswer? answer;
310-
if (this._waitForIngestionToComplete)
311-
{
312-
// using var cs = new CancellationTokenSource(this._maxIngestionWait);
313-
using var cs = new CancellationTokenSource(TimeSpan.FromMilliseconds(1));
314-
answer = await Do(cs.Token).ConfigureAwait(false);
315-
}
316-
else
317-
{
318-
answer = await Do(cancellationToken).ConfigureAwait(false);
319-
}
320-
321-
return answer?.Result ?? string.Empty;
367+
// TODO: support filters
368+
MemoryAnswer answer = await this._memory.AskAsync(
369+
question: question,
370+
index: index ?? this._defaultIndex,
371+
minRelevance: minRelevance,
372+
cancellationToken: cancellationToken).ConfigureAwait(false);
373+
return answer.Result;
322374
}
323375

324-
[SKFunction, Description("Remobe from memory all the information extracted from the given document ID")]
325-
public async Task<string> DeleteAsync()
376+
/// <summary>
377+
/// Remove from memory all the information extracted from the given document ID
378+
///
379+
/// Usage from prompts: '{{memory.delete ...}}'
380+
/// </summary>
381+
[SKFunction, Description("Remove from memory all the information extracted from the given document ID")]
382+
public Task DeleteAsync(
383+
[Description("The document to delete")]
384+
string documentId,
385+
[SKName(IndexParam), Description("Memories index where the document is stored"), DefaultValue("")]
386+
string? index = null,
387+
CancellationToken cancellationToken = default)
326388
{
327-
await Task.Delay(0).ConfigureAwait(false);
328-
throw new NotImplementedException();
389+
return this._memory.DeleteDocumentAsync(
390+
documentId: documentId,
391+
index: index ?? this._defaultIndex,
392+
cancellationToken: cancellationToken);
329393
}
330394
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="../../../service/Directory.Build.props"/>
4+
<Import Project="../../../service/Directory.Packages.props"/>
5+
<Import Project="../../../service/nuget-package.props"/>
6+
7+
<PropertyGroup>
8+
<TargetFramework>netstandard2.0</TargetFramework>
9+
<AssemblyName>Microsoft.KernelMemory.Plugin</AssemblyName>
10+
<RootNamespace>Microsoft.KernelMemory.Plugin</RootNamespace>
11+
<IsPackable>true</IsPackable>
12+
<PackageId>Microsoft.KernelMemory.Plugin</PackageId>
13+
<NoWarn>CS1591</NoWarn>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\..\service\Abstractions\Abstractions.csproj"/>
18+
<ProjectReference Include="..\WebClient\WebClient.csproj" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<PackageReference Include="Microsoft.SemanticKernel.Abstractions"/>
23+
</ItemGroup>
24+
25+
</Project>

dotnet/ClientLib/Models/Verify.cs renamed to clients/dotnet/WebClient/Internals/Verify.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using System;
44

5-
namespace Microsoft.KernelMemory.Models;
5+
namespace Microsoft.KernelMemory.Internals;
66

77
internal static class Verify
88
{

dotnet/ClientLib/MemoryWebClient.cs renamed to clients/dotnet/WebClient/MemoryWebClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
using System.Text.Json;
1111
using System.Threading;
1212
using System.Threading.Tasks;
13-
using Microsoft.KernelMemory.Models;
13+
using Microsoft.KernelMemory.Internals;
1414

15+
#pragma warning disable IDE0130 // reduce number of "using" statements
1516
// ReSharper disable once CheckNamespace
1617
namespace Microsoft.KernelMemory;
1718

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="../../../service/Directory.Build.props"/>
4+
<Import Project="../../../service/Directory.Packages.props"/>
5+
<Import Project="../../../service/nuget-package.props"/>
6+
7+
<PropertyGroup>
8+
<TargetFramework>netstandard2.0</TargetFramework>
9+
<AssemblyName>Microsoft.KernelMemory.WebClient</AssemblyName>
10+
<RootNamespace>Microsoft.KernelMemory</RootNamespace>
11+
<IsPackable>true</IsPackable>
12+
<PackageId>Microsoft.KernelMemory.WebClient</PackageId>
13+
<NoWarn>CS1591</NoWarn>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\..\service\Abstractions\Abstractions.csproj"/>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.SemanticKernel.Abstractions"/>
22+
</ItemGroup>
23+
24+
</Project>
File renamed without changes.

dotnet/InteractiveSetup/InteractiveSetup.csproj

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/001-dotnet-Serverless/001-dotnet-Serverless.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<AssemblyName/>
88
<RootNamespace/>
9+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
910
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
1011
<NoWarn>CA1050,CA2000,CA1707,CA1303,CA2007,CA1724</NoWarn>
1112
</PropertyGroup>
1213

1314
<ItemGroup>
14-
<ProjectReference Include="..\..\dotnet\CoreLib\CoreLib.csproj"/>
15-
<ProjectReference Include="..\..\dotnet\InteractiveSetup\InteractiveSetup.csproj"/>
15+
<ProjectReference Include="..\..\service\Core\Core.csproj" />
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="System.Memory.Data"/>
19+
<PackageReference Include="System.Memory.Data" Version="7.0.0"/>
2020
</ItemGroup>
2121

2222
<ItemGroup>

0 commit comments

Comments
 (0)