Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from microsoft:main #5

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ services:
- webapi/.env
environment:
- Authentication__Type=AzureAd
- SemanticMemory__Services__Qdrant__Endpoint=http://qdrant:6333
- SemanticMemory__Services__Qdrant__APIKey=chat-copilot
- SemanticMemory__Services__RabbitMq__Host=rabbitmq
- SemanticMemory__Services__RabbitMq__Port=5672
- SemanticMemory__Services__RabbitMq__Username=chat-copilot
- SemanticMemory__Services__RabbitMq__Password=chat-copilot
- SemanticMemory__ContentStorageType=AzureBlobs
- SemanticMemory__ImageOcrType=Tesseract
- SemanticMemory__TextGeneratorType=AzureOpenAI
- SemanticMemory__DataIngestion__OrchestrationType=Distributed
- SemanticMemory__DataIngestion__DistributedOrchestration__QueueType=RabbitMQ
- SemanticMemory__DataIngestion__VectorDbTypes__0=Qdrant
- SemanticMemory__DataIngestion__EmbeddingGeneratorTypes__0=AzureOpenAI
- SemanticMemory__Retrieval__EmbeddingGeneratorType=AzureOpenAI
- SemanticMemory__Retrieval__VectorDbType=Qdrant
- KernelMemory__Services__Qdrant__Endpoint=http://qdrant:6333
- KernelMemory__Services__Qdrant__APIKey=chat-copilot
- KernelMemory__Services__RabbitMq__Host=rabbitmq
- KernelMemory__Services__RabbitMq__Port=5672
- KernelMemory__Services__RabbitMq__Username=chat-copilot
- KernelMemory__Services__RabbitMq__Password=chat-copilot
- KernelMemory__ContentStorageType=AzureBlobs
- KernelMemory__ImageOcrType=Tesseract
- KernelMemory__TextGeneratorType=AzureOpenAI
- KernelMemory__DataIngestion__OrchestrationType=Distributed
- KernelMemory__DataIngestion__DistributedOrchestration__QueueType=RabbitMQ
- KernelMemory__DataIngestion__VectorDbTypes__0=Qdrant
- KernelMemory__DataIngestion__EmbeddingGeneratorTypes__0=AzureOpenAI
- KernelMemory__Retrieval__EmbeddingGeneratorType=AzureOpenAI
- KernelMemory__Retrieval__VectorDbType=Qdrant
- Plugins__1__Name=WebSearcher
- Plugins__1__ManifestDomain=http://web-searcher
- Plugins__1__Key=chat-copilot
Expand Down Expand Up @@ -117,21 +117,21 @@ services:
env_file:
- memorypipeline/.env
environment:
- SemanticMemory__Services__Qdrant__Endpoint=http://qdrant:6333
- SemanticMemory__Services__Qdrant__APIKey=chat-copilot
- SemanticMemory__Services__RabbitMq__Host=rabbitmq
- SemanticMemory__Services__RabbitMq__Port=5672
- SemanticMemory__Services__RabbitMq__Username=chat-copilot
- SemanticMemory__Services__RabbitMq__Password=chat-copilot
- SemanticMemory__ContentStorageType=AzureBlobs
- SemanticMemory__ImageOcrType=Tesseract
- SemanticMemory__TextGeneratorType=AzureOpenAI
- SemanticMemory__DataIngestion__OrchestrationType=Distributed
- SemanticMemory__DataIngestion__DistributedOrchestration__QueueType=RabbitMQ
- SemanticMemory__DataIngestion__VectorDbTypes__0=Qdrant
- SemanticMemory__DataIngestion__EmbeddingGeneratorTypes__0=AzureOpenAI
- SemanticMemory__Retrieval__EmbeddingGeneratorType=AzureOpenAI
- SemanticMemory__Retrieval__VectorDbType=Qdrant
- KernelMemory__Services__Qdrant__Endpoint=http://qdrant:6333
- KernelMemory__Services__Qdrant__APIKey=chat-copilot
- KernelMemory__Services__RabbitMq__Host=rabbitmq
- KernelMemory__Services__RabbitMq__Port=5672
- KernelMemory__Services__RabbitMq__Username=chat-copilot
- KernelMemory__Services__RabbitMq__Password=chat-copilot
- KernelMemory__ContentStorageType=AzureBlobs
- KernelMemory__ImageOcrType=Tesseract
- KernelMemory__TextGeneratorType=AzureOpenAI
- KernelMemory__DataIngestion__OrchestrationType=Distributed
- KernelMemory__DataIngestion__DistributedOrchestration__QueueType=RabbitMQ
- KernelMemory__DataIngestion__VectorDbTypes__0=Qdrant
- KernelMemory__DataIngestion__EmbeddingGeneratorTypes__0=AzureOpenAI
- KernelMemory__Retrieval__EmbeddingGeneratorType=AzureOpenAI
- KernelMemory__Retrieval__VectorDbType=Qdrant
depends_on:
qdrant:
condition: service_started
Expand Down
16 changes: 8 additions & 8 deletions docker/memorypipeline/.env.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Azure OpenAI embedding settings
SemanticMemory__Services__AzureOpenAIEmbedding__Deployment=
SemanticMemory__Services__AzureOpenAIEmbedding__Endpoint=
SemanticMemory__Services__AzureOpenAIEmbedding__APIKey=
KernelMemory__Services__AzureOpenAIEmbedding__Deployment=
KernelMemory__Services__AzureOpenAIEmbedding__Endpoint=
KernelMemory__Services__AzureOpenAIEmbedding__APIKey=

# Azure OpenAI text settings
SemanticMemory__Services__AzureOpenAIText__Deployment=
SemanticMemory__Services__AzureOpenAIText__Endpoint=
SemanticMemory__Services__AzureOpenAIText__APIKey=
KernelMemory__Services__AzureOpenAIText__Deployment=
KernelMemory__Services__AzureOpenAIText__Endpoint=
KernelMemory__Services__AzureOpenAIText__APIKey=

# Azure blob
SemanticMemory__Services__AzureBlobs__Auth=
SemanticMemory__Services__AzureBlobs__ConnectionString=
KernelMemory__Services__AzureBlobs__Auth=
KernelMemory__Services__AzureBlobs__ConnectionString=
16 changes: 8 additions & 8 deletions docker/webapi/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ AzureSpeech__Region=
AzureSpeech__Key=

# Azure OpenAI embedding settings
SemanticMemory__Services__AzureOpenAIEmbedding__Deployment=
SemanticMemory__Services__AzureOpenAIEmbedding__Endpoint=
SemanticMemory__Services__AzureOpenAIEmbedding__APIKey=
KernelMemory__Services__AzureOpenAIEmbedding__Deployment=
KernelMemory__Services__AzureOpenAIEmbedding__Endpoint=
KernelMemory__Services__AzureOpenAIEmbedding__APIKey=

# Azure OpenAI text settings
SemanticMemory__Services__AzureOpenAIText__Deployment=
SemanticMemory__Services__AzureOpenAIText__Endpoint=
SemanticMemory__Services__AzureOpenAIText__APIKey=
KernelMemory__Services__AzureOpenAIText__Deployment=
KernelMemory__Services__AzureOpenAIText__Endpoint=
KernelMemory__Services__AzureOpenAIText__APIKey=

# Azure blobs settings
SemanticMemory__Services__AzureBlobs__Auth=
SemanticMemory__Services__AzureBlobs__ConnectionString=
KernelMemory__Services__AzureBlobs__Auth=
KernelMemory__Services__AzureBlobs__ConnectionString=
50 changes: 50 additions & 0 deletions integration-tests/ChatTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using CopilotChat.WebApi.Models.Request;
using CopilotChat.WebApi.Models.Response;
using Xunit;
using static CopilotChat.WebApi.Models.Storage.CopilotChatMessage;

namespace ChatCopilotIntegrationTests;

public class ChatTests : ChatCopilotIntegrationTest
{
[Fact]
public async void ChatMessagePostSucceedsWithValidInput()
{
await this.SetUpAuth();

// Create chat session
var createChatParams = new CreateChatParameters() { Title = nameof(ChatMessagePostSucceedsWithValidInput) };
HttpResponseMessage response = await this._httpClient.PostAsJsonAsync("chats", createChatParams);
response.EnsureSuccessStatusCode();

var contentStream = await response.Content.ReadAsStreamAsync();
var createChatResponse = await JsonSerializer.DeserializeAsync<CreateChatResponse>(contentStream, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
Assert.NotNull(createChatResponse);

// Ask something to the bot
var ask = new Ask
{
Input = "Who is Satya Nadella?",
Variables = new KeyValuePair<string, string>[] { new("MessageType", ChatMessageType.Message.ToString()) }
};
response = await this._httpClient.PostAsJsonAsync($"chats/{createChatResponse.ChatSession.Id}/messages", ask);
response.EnsureSuccessStatusCode();

contentStream = await response.Content.ReadAsStreamAsync();
var askResult = await JsonSerializer.DeserializeAsync<AskResult>(contentStream, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
Assert.NotNull(askResult);
Assert.False(string.IsNullOrEmpty(askResult.Value));


// Clean up
response = await this._httpClient.DeleteAsync($"chats/{createChatResponse.ChatSession.Id}");
response.EnsureSuccessStatusCode();
}
}

28 changes: 22 additions & 6 deletions webapi/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public async Task<IActionResult> ChatAsync(
[FromServices] IKernel kernel,
[FromServices] IHubContext<MessageRelayHub> messageRelayHubContext,
[FromServices] CopilotChatPlanner planner,
[FromServices] AskConverter askConverter,
[FromServices] ChatSessionRepository chatSessionRepository,
[FromServices] ChatParticipantRepository chatParticipantRepository,
[FromServices] IAuthInfo authInfo,
Expand All @@ -108,7 +107,7 @@ public async Task<IActionResult> ChatAsync(
{
this._logger.LogDebug("Chat message received.");

return await this.HandleRequest(ChatFunctionName, kernel, messageRelayHubContext, planner, askConverter, chatSessionRepository, chatParticipantRepository, authInfo, ask, chatId.ToString());
return await this.HandleRequest(ChatFunctionName, kernel, messageRelayHubContext, planner, chatSessionRepository, chatParticipantRepository, authInfo, ask, chatId.ToString());
}

/// <summary>
Expand All @@ -135,7 +134,6 @@ public async Task<IActionResult> ProcessPlanAsync(
[FromServices] IKernel kernel,
[FromServices] IHubContext<MessageRelayHub> messageRelayHubContext,
[FromServices] CopilotChatPlanner planner,
[FromServices] AskConverter askConverter,
[FromServices] ChatSessionRepository chatSessionRepository,
[FromServices] ChatParticipantRepository chatParticipantRepository,
[FromServices] IAuthInfo authInfo,
Expand All @@ -144,7 +142,7 @@ public async Task<IActionResult> ProcessPlanAsync(
{
this._logger.LogDebug("plan request received.");

return await this.HandleRequest(ProcessPlanFunctionName, kernel, messageRelayHubContext, planner, askConverter, chatSessionRepository, chatParticipantRepository, authInfo, ask, chatId.ToString());
return await this.HandleRequest(ProcessPlanFunctionName, kernel, messageRelayHubContext, planner, chatSessionRepository, chatParticipantRepository, authInfo, ask, chatId.ToString());
}

/// <summary>
Expand All @@ -166,15 +164,14 @@ private async Task<IActionResult> HandleRequest(
IKernel kernel,
IHubContext<MessageRelayHub> messageRelayHubContext,
CopilotChatPlanner planner,
AskConverter askConverter,
ChatSessionRepository chatSessionRepository,
ChatParticipantRepository chatParticipantRepository,
IAuthInfo authInfo,
Ask ask,
string chatId)
{
// Put ask's variables in the context we will use.
var contextVariables = askConverter.GetContextVariables(ask);
var contextVariables = GetContextVariables(ask, authInfo, chatId);

// Verify that the chat exists and that the user has access to it.
ChatSession? chat = null;
Expand Down Expand Up @@ -415,6 +412,25 @@ await planner.Kernel.ImportOpenAIPluginFunctionsAsync(
return;
}

private static ContextVariables GetContextVariables(Ask ask, IAuthInfo authInfo, string chatId)
{
const string UserIdKey = "userId";
const string UserNameKey = "userName";
const string ChatIdKey = "chatId";

var contextVariables = new ContextVariables(ask.Input);
foreach (var variable in ask.Variables)
{
contextVariables.Set(variable.Key, variable.Value);
}

contextVariables.Set(UserIdKey, authInfo.UserId);
contextVariables.Set(UserNameKey, authInfo.Name);
contextVariables.Set(ChatIdKey, chatId);

return contextVariables;
}

/// <summary>
/// Dispose of the object.
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions webapi/Extensions/ServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ internal static void AddOptions<TOptions>(this IServiceCollection services, ICon
.PostConfigure(TrimStringProperties);
}

internal static IServiceCollection AddUtilities(this IServiceCollection services)
{
return services.AddScoped<AskConverter>();
}

internal static IServiceCollection AddPlugins(this IServiceCollection services, IConfiguration configuration)
{
var plugins = configuration.GetSection("Plugins").Get<List<Plugin>>() ?? new List<Plugin>();
Expand Down
1 change: 0 additions & 1 deletion webapi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static async Task Main(string[] args)
.AddOptions(builder.Configuration)
.AddPersistentChatStore()
.AddPlugins(builder.Configuration)
.AddUtilities()
.AddChatCopilotAuthentication(builder.Configuration)
.AddChatCopilotAuthorization();

Expand Down
41 changes: 0 additions & 41 deletions webapi/Utilities/AskConverter.cs

This file was deleted.

Loading