Skip to content

Commit

Permalink
Merge branch 'python/remove_kernel_base_class' of https://github.com/…
Browse files Browse the repository at this point in the history
…awharrison-28/semantic-kernel into python/remove_kernel_base_class
  • Loading branch information
awharrison-28 committed May 16, 2023
2 parents b7f7fce + 75f0905 commit f73c672
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ jobs:
- name: Archive artifacts ${{ matrix.os }}-${{ matrix.configuration }}
uses: actions/upload-artifact@v3
with:
name: drop-${{ matrix.os }}-dotnet${{matrix.dotnet-version}}-${{ matrix.configuration }}
name: drop-${{ matrix.os }}-${{ matrix.configuration }}
path: ./out
if: ${{ github.event_name == 'push' }}
2 changes: 1 addition & 1 deletion .github/workflows/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if [ -z "$buildAndRevisionNumber" ]; then
fi

propsVersionString=$(cat $propsFile | grep -i "<Version>");
regex="<Version>([0-9.]*)<\/Version>"
regex="<Version>([0-9.]*)-pre<\/Version>"
if [[ $propsVersionString =~ $regex ]]; then
propsVersion=${BASH_REMATCH[1]}
else
Expand Down
2 changes: 1 addition & 1 deletion dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="[1.6.3, )" />
<PackageVersion Include="Newtonsoft.Json" Version="[13.0.3, )" />
<PackageVersion Include="Google.Apis.CustomSearchAPI.v1" Version="[1.60.0.3001, )" />
<PackageVersion Include="Grpc.Net.Client" Version="2.52.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.53.0" />
<PackageVersion Include="protobuf-net" Version="3.2.16" />
<PackageVersion Include="protobuf-net.Reflection" Version="3.2.12" />
<!-- Symbols -->
Expand Down
6 changes: 4 additions & 2 deletions dotnet/nuget/nuget-package.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPackable>true</IsPackable>
<!-- Central version prefix - applies to all nuget packages -->
<Version>0.14</Version>
<!-- Central version prefix - applies to all nuget packages.
Only the numeric portion is used; '-pre' is ignored, but required
for packages with prerelease dependencies -->
<Version>0.14-pre</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0-preview.3.23174.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0-preview.3.23174.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-preview.3.23174.8" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.53.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.54.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private async Task RegisterPlannerSkillsAsync(CopilotChatPlanner planner, Planne
{
InnerHandler = new HttpClientHandler() { CheckCertificateRevocationList = true }
};
using HttpClient importHttpClient = new HttpClient(retryHandler, false);
using HttpClient importHttpClient = new(retryHandler, false);
importHttpClient.DefaultRequestHeaders.Add("User-Agent", "Microsoft.CopilotChat");
await planner.Kernel.ImportChatGptPluginSkillFromUrlAsync("KlarnaShoppingSkill", new Uri("https://www.klarna.com/.well-known/ai-plugin.json"),
importHttpClient);
Expand Down
6 changes: 3 additions & 3 deletions samples/apps/copilot-chat-app/webapi/CopilotChatApi.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<RepoRoot>$([System.IO.Path]::GetDirectoryName($([MSBuild]::GetPathOfFileAbove('.gitignore', '$(MSBuildThisFileDirectory)'))))</RepoRoot>
</PropertyGroup>
Expand All @@ -23,14 +23,14 @@
<PackageReference Include="Microsoft.SemanticKernel.Skills.Web" Version="0.13.442.1-preview" />

<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Identity" Version="1.9.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.16" />
<PackageReference Include="Microsoft.CognitiveServices.Speech" Version="1.28.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.33.0" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.0.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.10.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="2.11.0" />
<PackageReference Include="PdfPig" Version="0.1.8-alpha-20230423-3898f" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
Expand Down
55 changes: 40 additions & 15 deletions samples/apps/copilot-chat-app/webapi/Skills/ChatSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,23 +534,28 @@ private string OptimizeOpenApiSkillJson(string jsonContent, int tokenLimit, Plan

List<object> itemList = new();

// Summary (List) Object
// To stay within token limits, attempt to truncate the list of results
if (document.RootElement.ValueKind == JsonValueKind.Array)
// Some APIs will return a JSON response with one property key representing an embedded answer.
// Extract this value for further processing
string resultsDescriptor = "";

if (document.RootElement.ValueKind == JsonValueKind.Object)
{
foreach (JsonElement item in document.RootElement.EnumerateArray())
int propertyCount = 0;
foreach (JsonProperty property in document.RootElement.EnumerateObject())
{
int itemTokenCount = Utilities.TokenCount(item.ToString());
propertyCount++;
}

if (jsonTokenLimit - itemTokenCount > 0)
{
itemList.Add(item);
jsonTokenLimit -= itemTokenCount;
}
else
{
break;
}
if (propertyCount == 1)
{
// Save property name for result interpolation
JsonProperty firstProperty = document.RootElement.EnumerateObject().First();
jsonTokenLimit -= Utilities.TokenCount(firstProperty.Name);
resultsDescriptor = string.Format(CultureInfo.InvariantCulture, "{0}: ", firstProperty.Name);

// Extract object to be truncated
JsonElement value = firstProperty.Value;
document = JsonDocument.Parse(value.GetRawText());
}
}

Expand All @@ -574,8 +579,28 @@ private string OptimizeOpenApiSkillJson(string jsonContent, int tokenLimit, Plan
}
}

// Summary (List) Object
// To stay within token limits, attempt to truncate the list of results
if (document.RootElement.ValueKind == JsonValueKind.Array)
{
foreach (JsonElement item in document.RootElement.EnumerateArray())
{
int itemTokenCount = Utilities.TokenCount(item.ToString());

if (jsonTokenLimit - itemTokenCount > 0)
{
itemList.Add(item);
jsonTokenLimit -= itemTokenCount;
}
else
{
break;
}
}
}

return itemList.Count > 0
? JsonSerializer.Serialize(itemList)
? string.Format(CultureInfo.InvariantCulture, "{0}{1}", resultsDescriptor, JsonSerializer.Serialize(itemList))
: string.Format(CultureInfo.InvariantCulture, "JSON response for {0} is too large to be consumed at this time.", lastSkillInvoked);
}

Expand Down
2 changes: 1 addition & 1 deletion samples/apps/copilot-chat-app/webapp/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ export const Constants = {
},
// For a list of Microsoft Graph permissions, see https://learn.microsoft.com/en-us/graph/permissions-reference.
// Your application registration will need to be granted these permissions in Azure Active Directory.
msGraphScopes: ['Calendars.Read', 'Mail.Read', 'Tasks.ReadWrite', 'User.Read'],
msGraphScopes: ['Calendars.Read', 'Mail.Read', 'Mail.Send', 'Tasks.ReadWrite', 'User.Read'],
adoScopes: ['vso.work'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export const PluginConnector: React.FC<PluginConnectorProps> = ({
const classes = useClasses();

const usernameRequired = authRequirements.username;
const emailRequired = authRequirements.email;
const passwordRequired = authRequirements.password;
const accessTokenRequired = authRequirements.personalAccessToken;
const msalRequired = authRequirements.Msal;
const oauthRequired = authRequirements.OAuth;

const [username, setUsername] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [accessToken, setAccessToken] = useState('');
const [apiPropertiesInput, setApiRequirementsInput] = useState(apiProperties);
Expand Down Expand Up @@ -102,6 +104,7 @@ export const PluginConnector: React.FC<PluginConnectorProps> = ({
connectPlugin({
plugin: name,
username: username,
email: email,
password: password,
accessToken: accessToken,
apiProperties: apiPropertiesInput,
Expand Down Expand Up @@ -164,7 +167,7 @@ export const PluginConnector: React.FC<PluginConnectorProps> = ({
</div>
</>
)}
{(usernameRequired || accessTokenRequired) && (
{(usernameRequired || emailRequired || accessTokenRequired) && (
<Body1Strong> Log in to {name} to continue</Body1Strong>
)}
{(msalRequired || oauthRequired) && (
Expand All @@ -188,6 +191,20 @@ export const PluginConnector: React.FC<PluginConnectorProps> = ({
/>
</>
)}
{emailRequired && (
<>
<Input
required
type="text"
id={'plugin-email-input'}
value={email}
onChange={(_e, input) => {
setEmail(input.value);
}}
placeholder={`Enter your ${name} email`}
/>
</>
)}
{passwordRequired && (
<>
<Input
Expand Down
20 changes: 10 additions & 10 deletions samples/apps/copilot-chat-app/webapp/src/libs/useChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ChatState } from '../redux/features/conversations/ChatState';
import { Conversations } from '../redux/features/conversations/ConversationsState';
import {
addConversation,
incrementBotProfilePictureIndex,
setConversations,
setSelectedConversation,
updateConversation,
Expand Down Expand Up @@ -35,7 +34,7 @@ export const useChat = () => {
const { instance, accounts } = useMsal();
const account = useAccount(accounts[0] || {});
const sk = useSemanticKernel(process.env.REACT_APP_BACKEND_URI as string);
const { botProfilePictureIndex } = useAppSelector((state: RootState) => state.conversations);
const { conversations } = useAppSelector((state: RootState) => state.conversations);

const connectors = useConnectors();
const botService = new BotService(process.env.REACT_APP_BACKEND_URI as string);
Expand Down Expand Up @@ -81,10 +80,9 @@ export const useChat = () => {
messages: chatMessages,
audience: [loggedInUser],
botTypingTimestamp: 0,
botProfilePicture: botProfilePictures.at(botProfilePictureIndex) ?? '/assets/bot-icon-1.png',
botProfilePicture: getBotProfilePicture(Object.keys(conversations).length)
};

dispatch(incrementBotProfilePictureIndex());
dispatch(addConversation(newChat));
dispatch(setSelectedConversation(newChat.id));

Expand Down Expand Up @@ -173,7 +171,7 @@ export const useChat = () => {
);

if (chatSessions.length > 0) {
const conversations: Conversations = {};
const loadedConversations: Conversations = {};
for (const index in chatSessions) {
const chatSession = chatSessions[index];
const chatMessages = await chatService.getChatMessagesAsync(
Expand All @@ -187,19 +185,17 @@ export const useChat = () => {
// so we need to reverse the order for render
const orderedMessages = chatMessages.reverse();

conversations[chatSession.id] = {
loadedConversations[chatSession.id] = {
id: chatSession.id,
title: chatSession.title,
audience: [loggedInUser],
messages: orderedMessages,
botTypingTimestamp: 0,
botProfilePicture: botProfilePictures[botProfilePictureIndex],
botProfilePicture: getBotProfilePicture(Object.keys(loadedConversations).length),
};

dispatch(incrementBotProfilePictureIndex());
}

dispatch(setConversations(conversations));
dispatch(setConversations(loadedConversations));
dispatch(setSelectedConversation(chatSessions[0].id));
} else {
// No chats exist, create first chat window
Expand Down Expand Up @@ -238,6 +234,10 @@ export const useChat = () => {
});
};

const getBotProfilePicture = (index: number) => {
return botProfilePictures[index % botProfilePictures.length];
};

return {
getAudienceMemberForId,
createChat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ export type Conversations = {
export interface ConversationsState {
conversations: Conversations;
selectedId: string;
botProfilePictureIndex: number;
}

export const initialState: ConversationsState = {
conversations: {},
selectedId: '',
botProfilePictureIndex: 0,
};

export type UpdateConversationPayload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export const conversationsSlice = createSlice({
name: 'conversations',
initialState,
reducers: {
incrementBotProfilePictureIndex: (state: ConversationsState) => {
state.botProfilePictureIndex = ++state.botProfilePictureIndex % 5;
},
setConversations: (state: ConversationsState, action: PayloadAction<Conversations>) => {
state.conversations = action.payload;
},
Expand Down Expand Up @@ -50,7 +47,6 @@ export const conversationsSlice = createSlice({
});

export const {
incrementBotProfilePictureIndex,
setConversations,
editConversationTitle,
setSelectedConversation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const enum AuthHeaderTags {

export type PluginAuthRequirements = {
username?: boolean;
email?: boolean;
password?: boolean;
personalAccessToken?: boolean;
OAuth?: boolean;
Expand Down Expand Up @@ -79,18 +80,18 @@ export const initialState: PluginsState = {
Jira: {
name: Plugins.Jira,
publisher: 'Atlassian',
description: 'Authorize Copilot Chat to post and link with Jira when there are issues.',
description: 'Authorize Copilot Chat to link with Jira and retrieve specific issues by providing the issue key.',
enabled: false,
authRequirements: {
username: true,
email: true,
personalAccessToken: true,
helpLink: 'https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/',
},
icon: JiraIcon,
headerTag: AuthHeaderTags.Jira,
apiProperties: {
'jira-server-url': {
description: 'base server url',
description: 'server url, i.e. "https://<your-domain>.atlassian.net/rest/api/latest/"',
required: true,
helpLink: 'https://confluence.atlassian.com/adminjiraserver/configuring-the-base-url-938847830.html',
},
Expand Down Expand Up @@ -137,6 +138,7 @@ export const initialState: PluginsState = {
export type EnablePluginPayload = {
plugin: Plugins;
username?: string;
email?: string;
password?: string;
accessToken?: string;
apiProperties?: AdditionalApiProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const pluginsState = createSlice({
break;
case Plugins.Jira:
plugin = state.Jira;
authData = `${action.payload.username}:${action.payload.accessToken}`;
authData = `${action.payload.email}:${action.payload.accessToken}`;
break;
case Plugins.GitHub:
plugin = state.GitHub;
Expand Down
2 changes: 1 addition & 1 deletion samples/apps/hugging-face-http-server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cryptography==39.0.2
dataclasses==0.6
diffusers==0.2.2
filelock==3.4.1
Flask==2.0.3
Flask==2.2.5
huggingface-hub==0.4.0
idna==3.4
importlib-metadata==4.8.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Identity" Version="1.9.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
Expand Down

0 comments on commit f73c672

Please sign in to comment.