Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/PYTHON' into lilyydu/invokes
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyydu committed Feb 20, 2024
2 parents 692e432 + 3b9aefe commit 6669d33
Show file tree
Hide file tree
Showing 37 changed files with 658 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup NodeJS ${{ env.node-version }}
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ env.node-version }}
- name: Install Dependencies
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
parallel: true
files: ${{ env.SOLUTION_DIR }}TestResults/coverage/lcov.info
- name: Upload Tests
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: testresults-dotnet-${{ env.dotnet-version }}
path: ${{ env.SOLUTION_DIR }}TestResults
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
reporttypes: 'HtmlInline;lcov'
toolpath: ${{ env.SOLUTION_DIR }}report-generator-tool
- name: Upload Tests
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: testresults-dotnet-${{ matrix.dotnet-version }}
path: ${{ env.SOLUTION_DIR }}TestResults
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Publish
run: dotnet nuget push *.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/microsoft/index.json --skip-duplicate --no-symbols
- name: Upload
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: nupkg-dotnet-${{ matrix.dotnet-version }}
path: dotnet/packages/Microsoft.TeamsAI/*.nupkg
2 changes: 1 addition & 1 deletion .github/workflows/js-build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup NodeJS ${{ matrix.node-version }}
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: SARIF file
path: results.sarif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.12" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="7.0.0" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.21.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="xunit" Version="2.6.6" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -42,6 +44,15 @@ public TeamsAdapter(
{
HttpClientFactory = new TeamsHttpClientFactory(httpClientFactory);
}

/// <inheritdoc />
public new async Task ProcessAsync(HttpRequest httpRequest, HttpResponse httpResponse, IBot bot, CancellationToken cancellationToken = default)
{
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
ProductInfoHeaderValue productInfo = new("teamsai-dotnet", version);
httpResponse.Headers.Add("User-Agent", productInfo.ToString());
await base.ProcessAsync(httpRequest, httpResponse, bot, cancellationToken);
}
}

internal class TeamsHttpClientFactory : IHttpClientFactory
Expand Down
6 changes: 4 additions & 2 deletions getting-started/CONCEPTS/DATA-SOURCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ Within each Action Planner’s prompt management system, a list of data sources

Our simplest example (primarily for testing) is `TextDataSource`, which adds a static block of text to a prompt.

Our most complex example is the `VectraDataSource` in the Chef Bot sample, which uses an external library called Vectra.
Our most complex Javascript example is the `VectraDataSource` in the Chef Bot sample, which uses an external library called [Vectra](https://github.com/Stevenic/vectra).

### Customized Example of VectraDataSource
Our most complex C# example is the `KernelMemoryDataSource` in the Chef Bot sample, which uses an external library called [Kernel Memory](https://github.com/microsoft/kernel-memory).

### Customized Examples

#### Javascript
Here is an example of the configuration for the
Expand Down
4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@azure/logger": "^1.0.2",
"@azure/ms-rest-js": "2.7.0",
"@microsoft/api-extractor": "^7.39.4",
"@microsoft/api-extractor": "^7.40.1",
"@standardlabs/is-private": "^1.0.1",
"@types/jsonwebtoken": "9.0.4",
"@types/lodash": "^4.14.202",
Expand All @@ -43,7 +43,7 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-security": "^1.7.1",
"exorcist": "^2.0.0",
"mocha": "^10.2.0",
"mocha": "^10.3.0",
"mocha-junit-reporter": "^2.0.0",
"ms-rest-azure": "^3.0.2",
"npm-run-all": "^4.1.5",
Expand Down
10 changes: 6 additions & 4 deletions js/packages/teams-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"dependencies": {
"@azure/msal-node": "^2.6.2",
"@azure/msal-node": "^2.6.3",
"axios": "^1.6.7",
"botbuilder": "^4.22.1",
"botbuilder-dialogs": "^4.22.1",
"gpt-3-encoder": "^1.1.4",
"json-colorizer": "^2.2.2",
"jsonschema": "1.4.1",
"openai": "^4.26.1",
"openai": "^4.27.0",
"uuid": "^9.0.1",
"yaml": "^2.3.4"
},
Expand All @@ -38,13 +38,15 @@
},
"devDependencies": {
"@types/assert": "^1.5.10",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.16",
"@types/node": "^20.11.19",
"@types/uuid": "^9.0.8",
"eslint": "^8.56.0",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.2",
"mocha": "10.2.0",
"mocha": "10.3.0",
"nyc": "^15.1.0",
"rimraf": "5.0.5",
"shx": "^0.3.4",
Expand Down
2 changes: 1 addition & 1 deletion js/packages/teams-ai/src/AdaptiveCards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('AdaptiveCards', () => {
let selector: RouteSelector;
let handler: any;
let addRouteStub: sinon.SinonStub;
let adapter = new TestAdapter();
const adapter = new TestAdapter();

beforeEach(() => {
app = new Application();
Expand Down
72 changes: 72 additions & 0 deletions js/packages/teams-ai/src/TeamsAdapter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import http from 'http';
import assert from 'assert';
import sinon from 'sinon';
import axios from 'axios';
import express from 'express';

import { TeamsAdapter } from './TeamsAdapter';

describe('TeamsAdapter', () => {
let sandbox: sinon.SinonSandbox;
const app = express();
let server: http.Server;
let adapter: TeamsAdapter;

beforeEach(() => {
sandbox = sinon.createSandbox();
adapter = new TeamsAdapter();

app.post('/api/messages', async (req, res) => {
await adapter.process(req, res, async () => {});
});

server = app.listen(80);
});

afterEach(() => {
sandbox.reset();
server.close();
});

describe('process', () => {
it('should add `User-Agent` header to response', async () => {
sandbox.stub(adapter, <any>'processActivity').resolves({ status: 200 });
let userAgent: string | undefined;

try {
const res = await axios.post('/api/messages', {
type: 'invoke',
localTimezone: 'America/Los_Angeles',
callerId: 'test',
serviceUrl: 'test',
channelId: 'test',
from: {
id: '123456',
name: 'test'
},
conversation: {
id: '123456',
name: 'test',
conversationType: 'test',
isGroup: false
},
recipient: {
id: '123456',
name: 'test'
},
text: '',
label: 'invoke',
valueType: 'invoke'
});

userAgent = res.headers['user-agent'];
} catch (err) {
if (err instanceof axios.AxiosError) {
userAgent = err.response?.headers['user-agent'];
}
}

assert.strict.equal(userAgent, adapter.userAgent);
});
});
});
33 changes: 32 additions & 1 deletion js/packages/teams-ai/src/TeamsAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
ConfigurationBotFrameworkAuthentication,
ConfigurationBotFrameworkAuthenticationOptions,
ConfigurationServiceClientCredentialFactory,
ConfigurationServiceClientCredentialFactoryOptions
ConfigurationServiceClientCredentialFactoryOptions,
Request,
Response,
TurnContext
} from 'botbuilder';

import {
Expand All @@ -27,6 +30,7 @@ import {
} from 'botframework-connector';

import packageInfo from '../package.json';
import { INodeSocket, INodeBuffer } from 'botframework-streaming';

const USER_AGENT = `teamsai-js/${packageInfo.version}`;

Expand All @@ -39,6 +43,10 @@ export class TeamsAdapter extends CloudAdapter {
*/
public readonly credentialsFactory: ServiceClientCredentialsFactory;

public get userAgent(): string {
return USER_AGENT;
}

constructor(
readonly botFrameworkAuthConfig?: ConfigurationBotFrameworkAuthenticationOptions,
credentialsFactory?: ServiceClientCredentialsFactory,
Expand All @@ -65,4 +73,27 @@ export class TeamsAdapter extends CloudAdapter {
botFrameworkAuthConfig as ConfigurationServiceClientCredentialFactoryOptions
);
}

async process(req: Request, res: Response, logic: (context: TurnContext) => Promise<void>): Promise<void>;
async process(
req: Request,
socket: INodeSocket,
head: INodeBuffer,
logic: (context: TurnContext) => Promise<void>
): Promise<void>;
async process(
req: Request,
resOrSocket: Response | INodeSocket,
logicOrHead: ((context: TurnContext) => Promise<void>) | INodeBuffer,
maybeLogic?: (context: TurnContext) => Promise<void>
): Promise<void> {
if ('header' in resOrSocket && typeof logicOrHead === 'function') {
resOrSocket.header('User-Agent', USER_AGENT);
return super.process(req, resOrSocket, logicOrHead);
}

if ('connecting' in resOrSocket && typeof logicOrHead !== 'function' && !!maybeLogic) {
return super.process(req, resOrSocket, logicOrHead, maybeLogic);
}
}
}
2 changes: 1 addition & 1 deletion js/samples/01.messaging.a.echoBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"botbuilder": "^4.22.1",
"@microsoft/teams-ai": "~1.1.0",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"botbuilder": "^4.22.1",
"@microsoft/teams-ai": "~1.1.0",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0",
"axios": "^1.6.7"
Expand Down
2 changes: 1 addition & 1 deletion js/samples/03.adaptiveCards.a.typeAheadBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"botbuilder": "^4.22.1",
"@microsoft/teams-ai": "~1.1.0",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0",
"axios": "^1.6.7"
Expand Down
4 changes: 2 additions & 2 deletions js/samples/04.ai.a.teamsChefBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"@microsoft/teams-ai": "~1.1.0",
"@microsoft/teamsfx": "^2.3.0",
"botbuilder": "^4.22.1",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0",
"vectra": "^0.5.5"
},
"devDependencies": {
"@types/dotenv": "6.1.1",
"@types/restify": "8.5.12",
"@types/node": "^20.11.16",
"@types/node": "^20.11.19",
"ts-node": "^10.9.2",
"env-cmd": "^10.1.0",
"nodemon": "~1.19.4",
Expand Down
2 changes: 1 addition & 1 deletion js/samples/04.ai.b.messageExtensions.AI-ME/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"botbuilder": "^4.22.1",
"@microsoft/teams-ai": "~1.1.0",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion js/samples/04.ai.c.actionMapping.lightBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"botbuilder": "^4.22.1",
"@microsoft/teams-ai": "~1.1.0",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion js/samples/04.ai.d.chainedActions.listBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@microsoft/teams-ai": "~1.1.0",
"botbuilder": "^4.22.1",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion js/samples/04.ai.e.chainedActions.devOpsBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"botbuilder": "^4.22.1",
"@microsoft/teams-ai": "~1.1.0",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0"
},
Expand Down
4 changes: 2 additions & 2 deletions js/samples/04.ai.f.vision.cardGazer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"@microsoft/teams-ai": "~1.1.0",
"@microsoft/teamsfx": "^2.3.0",
"botbuilder": "^4.22.1",
"dotenv": "^16.4.1",
"dotenv": "^16.4.2",
"replace": "~1.2.0",
"restify": "~11.1.0"
},
"devDependencies": {
"@types/dotenv": "6.1.1",
"@types/restify": "8.5.12",
"@types/node": "^20.11.16",
"@types/node": "^20.11.19",
"ts-node": "^10.9.2",
"env-cmd": "^10.1.0",
"nodemon": "~1.19.4",
Expand Down
Loading

0 comments on commit 6669d33

Please sign in to comment.