Skip to content

Commit b224c21

Browse files
kazarogerbarreto
authored andcommitted
Integration tests to reproduce BadRequest issue (microsoft#1061)
### Motivation and Context This PR provides integration tests to reproduce the issue microsoft#1050 ### Description These notes will help understanding how your code works. Thanks! --> Co-authored-by: Roger Barreto <[email protected]>
1 parent 69bbe7b commit b224c21

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

‎dotnet/src/Connectors/Connectors.Memory.Postgres/PostgresMemoryStore.cs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ public async Task RemoveBatchAsync(string collectionName, IEnumerable<string> ke
149149
using NpgsqlConnection dbConnection = await this._dataSource.OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
150150

151151
IAsyncEnumerable<(DatabaseEntry, double)> results = this._dbConnector.GetNearestMatchesAsync(
152-
dbConnection,
153-
collectionName: collectionName,
154-
embeddingFilter: new Vector(embedding.Vector.ToArray()),
155-
limit: limit,
156-
minRelevanceScore: minRelevanceScore,
157-
withEmbeddings: withEmbeddings,
158-
cancellationToken: cancellationToken);
152+
dbConnection,
153+
collectionName: collectionName,
154+
embeddingFilter: new Vector(embedding.Vector.ToArray()),
155+
limit: limit,
156+
minRelevanceScore: minRelevanceScore,
157+
withEmbeddings: withEmbeddings,
158+
cancellationToken: cancellationToken);
159159

160160
await foreach (var (entry, cosineSimilarity) in results.ConfigureAwait(false))
161161
{
162162
MemoryRecord record = MemoryRecord.FromJsonMetadata(
163-
json: entry.MetadataString,
164-
withEmbeddings && entry.Embedding != null ? new Embedding<float>(entry.Embedding!.ToArray()) : Embedding<float>.Empty,
165-
entry.Key,
166-
ParseTimestamp(entry.Timestamp));
163+
json: entry.MetadataString,
164+
withEmbeddings && entry.Embedding != null ? new Embedding<float>(entry.Embedding!.ToArray()) : Embedding<float>.Empty,
165+
entry.Key,
166+
ParseTimestamp(entry.Timestamp));
167167
yield return (record, cosineSimilarity);
168168
}
169169
}

‎dotnet/src/IntegrationTests/Connectors/OpenAI/OpenAICompletionTests.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ public async Task OpenAIChatAsTextTestAsync(string prompt, string expectedAnswer
7777
Assert.Contains(expectedAnswerContains, actual.Result, StringComparison.OrdinalIgnoreCase);
7878
}
7979

80+
[Fact]
81+
public async Task CanUseOpenAiChatForTextCompletionAsync()
82+
{
83+
// Note: we use OpenAi Chat Completion and GPT 3.5 Turbo
84+
IKernel target = Kernel.Builder.WithLogger(this._logger).Build();
85+
this.ConfigureChatOpenAI(target);
86+
87+
var func = target.CreateSemanticFunction(
88+
"List the two planets after '{{$input}}', excluding moons, using bullet points.");
89+
90+
var result = await func.InvokeAsync("Jupiter");
91+
92+
Assert.NotNull(result);
93+
Assert.False(result.ErrorOccurred, result.LastErrorDescription);
94+
Assert.Contains("Saturn", result.Result, StringComparison.InvariantCultureIgnoreCase);
95+
Assert.Contains("Uranus", result.Result, StringComparison.InvariantCultureIgnoreCase);
96+
}
97+
8098
[Theory]
8199
[InlineData(false, "Where is the most famous fish market in Seattle, Washington, USA?", "Pike Place")]
82100
[InlineData(true, "Where is the most famous fish market in Seattle, Washington, USA?", "Pike Place")]

0 commit comments

Comments
 (0)