Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
colombod committed Oct 9, 2023
1 parent e154289 commit b2d778e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
13 changes: 0 additions & 13 deletions src/Microsoft.DotNet.Interactive.AIUtilities/EnumerableAI.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Reactive.Disposables;
using System.Reactive.Linq;
using Microsoft.DeepDev;
using System.Reactive.Linq;

namespace Microsoft.DotNet.Interactive.AIUtilities;

public static class ObservableAI
{
public static class Text {

public static IEnumerable<KeyValuePair<T, float>> ScoreBySimilarityTo<T>(this IEnumerable<T> source, T value,
ISimilarityComparer<T> comparer)
{
return source.Select(item => new KeyValuePair<T, float>(item, comparer.Score(item, value)));
}

public static IObservable<string> ChunkByTokenCountWithOverlap(this IObservable<string> source, ITokenizer tokenizer, int maxTokenCount, int overlapTokenCount)
{
if (maxTokenCount <= overlapTokenCount)
Expand All @@ -21,7 +27,7 @@ public static IObservable<string> ChunkByTokenCountWithOverlap(this IObservable<
{
return System.Reactive.Linq.Observable.Create<string>(o =>
{
var chunks = tokenizer.ChunkByTokenCountWithOverlap(text ,maxTokenCount, overlapTokenCount);
var chunks = tokenizer.ChunkByTokenCountWithOverlap(text, maxTokenCount, overlapTokenCount);
foreach (var chunk in chunks)
{
o.OnNext(chunk);
Expand All @@ -36,7 +42,6 @@ public static IObservable<string> ChunkByTokenCountWithOverlap(this IObservable<

public static IObservable<string> ChunkByTokenCount(this IObservable<string> source, ITokenizer tokenizer, int maxTokenCount)
{
return source.ChunkByTokenCountWithOverlap(tokenizer, maxTokenCount,0 );
}
}

return source.ChunkByTokenCountWithOverlap(tokenizer, maxTokenCount, 0);
}
}

0 comments on commit b2d778e

Please sign in to comment.