Skip to content

Commit

Permalink
Merge branch 'main' into lilyydu/search-command-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyydu committed Apr 17, 2024
2 parents ff5fa14 + f1a465a commit 4a59b5d
Show file tree
Hide file tree
Showing 189 changed files with 649 additions and 377 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Initialize CodeQL
uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/init@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
languages: csharp
- name: Setup .NET
Expand All @@ -50,6 +50,6 @@ jobs:
working-directory: dotnet/packages/Microsoft.TeamsAI/
run: dotnet build Microsoft.Teams.AI.sln --configuration Release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/analyze@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
category: "/language:csharp"
4 changes: 2 additions & 2 deletions .github/workflows/js-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Initialize CodeQL
uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/init@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
languages: javascript
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/analyze@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
category: "/language:javascript"
4 changes: 2 additions & 2 deletions .github/workflows/python-codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
- name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
- name: Initialize CodeQL
uses: github/codeql-action/init@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/init@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
languages: python
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/analyze@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
category: "/language:python"
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4355270be187e1b672a7a1c7c7bae5afdc1ab94a # v3.24.10
uses: github/codeql-action/upload-sarif@df5a14dc28094dc936e103b37d749c6628682b60 # v3.25.0
with:
sarif_file: results.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<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.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<PackageReference Include="Microsoft.Bot.Builder" Version="4.22.2" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.22.2" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.22.2" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.60.1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.60.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.ML.Tokenizers" Version="0.22.0-preview.24179.1" />
<PackageReference Include="System.Text.Json" Version="7.0.4" />
Expand Down
8 changes: 4 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"openai": "4.28.4"
},
"devDependencies": {
"@azure/logger": "^1.1.1",
"@azure/logger": "^1.1.2",
"@azure/ms-rest-js": "2.7.0",
"@microsoft/api-extractor": "^7.43.0",
"@microsoft/api-extractor": "^7.43.1",
"@standardlabs/is-private": "^1.0.1",
"@types/jsonwebtoken": "9.0.4",
"@types/lodash": "^4.17.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.5",
"@types/node": "^20.12.7",
"@types/sinon": "^10.0.19",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand All @@ -42,7 +42,7 @@
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^46.10.1",
"eslint-plugin-mocha": "^10.4.1",
"eslint-plugin-mocha": "^10.4.2",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint": "^8.57.0",
Expand Down
4 changes: 2 additions & 2 deletions js/packages/teams-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"openai": "4.28.4"
},
"dependencies": {
"@azure/msal-node": "^2.6.6",
"@azure/msal-node": "^2.7.0",
"axios": "^1.6.8",
"botbuilder-dialogs": "^4.22.1",
"botframework-connector": "^4.22.1",
Expand All @@ -49,7 +49,7 @@
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.4",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.5",
"@types/node": "^20.12.7",
"@types/uuid": "^9.0.8",
"botbuilder-core": "^4.22.1",
"eslint": "^8.57.0",
Expand Down
56 changes: 47 additions & 9 deletions js/packages/teams-ai/src/embeddings/OpenAIEmbeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import { CreateEmbeddingRequest, CreateEmbeddingResponse, OpenAICreateEmbeddingR
* Base model options common to both OpenAI and Azure OpenAI services.
*/
export interface BaseOpenAIEmbeddingsOptions {
/**
* Optional. Number of dimensions to use when generating embeddings.
* @remarks
* Only valid for embedding models that support dynamic dimensionality.
*/
dimensions?: number;

/**
* Optional. Whether to log requests to the console.
* @remarks
Expand Down Expand Up @@ -47,9 +54,7 @@ export interface OpenAIEmbeddingsOptions extends BaseOpenAIEmbeddingsOptions {
apiKey: string;

/**
* Model to use for completion.
* @remarks
* For Azure OpenAI this is the name of the deployment to use.
* Embeddings Model to use.
*/
model: string;

Expand All @@ -66,6 +71,35 @@ export interface OpenAIEmbeddingsOptions extends BaseOpenAIEmbeddingsOptions {
endpoint?: string;
}

/**
* Options for configuring an embeddings object that calls an `OpenAI` compliant endpoint.
* @remarks
* The endpoint should comply with the OpenAPI spec for OpenAI's API:
*
* https://github.com/openai/openai-openapi
*
* And an example of a compliant endpoint is LLaMA.cpp's reference server:
*
* https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md
*
*/
export interface OpenAILikeEmbeddingsOptions extends BaseOpenAIEmbeddingsOptions {
/**
* Endpoint of the embeddings server to call.
*/
endpoint: string;

/**
* Embeddings Model to use.
*/
model: string;

/**
* Optional. API key to use when calling the embeddings server.
*/
apiKey?: string;
}

/**
* Options for configuring an `OpenAIEmbeddings` to generate embeddings using an Azure OpenAI hosted model.
*/
Expand Down Expand Up @@ -103,11 +137,11 @@ export class OpenAIEmbeddings implements EmbeddingsModel {
/**
* Options the client was configured with.
*/
public readonly options: OpenAIEmbeddingsOptions | AzureOpenAIEmbeddingsOptions;
public readonly options: OpenAIEmbeddingsOptions | AzureOpenAIEmbeddingsOptions | OpenAILikeEmbeddingsOptions;

/**
* Creates a new `OpenAIEmbeddings` instance.
* @param {OpenAIEmbeddingsOptions | AzureOpenAIEmbeddingsOptions} options Options for configuring the embeddings client.
* @param {OpenAIEmbeddingsOptions | AzureOpenAIEmbeddingsOptions | OpenAILikeEmbeddingsOptions} options Options for configuring the embeddings client.
*/
public constructor(options: OpenAIEmbeddingsOptions | AzureOpenAIEmbeddingsOptions) {
// Check for azure config
Expand Down Expand Up @@ -162,12 +196,16 @@ export class OpenAIEmbeddings implements EmbeddingsModel {
console.log(Colorize.output(inputs));
}

const startTime = Date.now();
const response = await this.createEmbeddingRequest({
const request: CreateEmbeddingRequest = {
model: model,
input: inputs
});
};
if (this.options.dimensions) {
request.dimensions = this.options.dimensions;
}

const startTime = Date.now();
const response = await this.createEmbeddingRequest(request);
if (this.options.logRequests) {
console.log(Colorize.title('RESPONSE:'));
console.log(Colorize.value('status', response.status));
Expand Down Expand Up @@ -236,7 +274,7 @@ export class OpenAIEmbeddings implements EmbeddingsModel {
if (this._useAzure) {
const options = this.options as AzureOpenAIEmbeddingsOptions;
requestConfig.headers['api-key'] = options.azureApiKey;
} else {
} else if ((this.options as OpenAIEmbeddingsOptions).apiKey){
const options = this.options as OpenAIEmbeddingsOptions;
requestConfig.headers['Authorization'] = `Bearer ${options.apiKey}`;
if (options.organization) {
Expand Down
1 change: 1 addition & 0 deletions js/packages/teams-ai/src/internals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export interface CreateEmbeddingRequest {
model: string;
encoding_format?: string;
user?: string;
dimensions?: number;
}

/**
Expand Down
62 changes: 57 additions & 5 deletions js/packages/teams-ai/src/models/OpenAIModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export interface BaseOpenAIModelOptions {
*/
logRequests?: boolean;

/**
* Optional. Forces the model return a specific response format.
* @remarks
* This can be used to force the model to always return a valid JSON object.
*/
responseFormat?: { "type": "json_object" };

/**
* Optional. Retry policy to use when calling the OpenAI API.
* @remarks
Expand All @@ -44,6 +51,13 @@ export interface BaseOpenAIModelOptions {
*/
requestConfig?: AxiosRequestConfig;

/**
* Optional. A static seed to use when making model calls.
* @remarks
* The default is to use a random seed. Specifying a seed will make the model deterministic.
*/
seed?: number;

/**
* Optional. Whether to use `system` messages when calling the OpenAI API.
* @remarks
Expand All @@ -52,6 +66,7 @@ export interface BaseOpenAIModelOptions {
* prompt to be sent as `user` messages instead.
*/
useSystemMessages?: boolean;

}

/**
Expand Down Expand Up @@ -83,6 +98,35 @@ export interface OpenAIModelOptions extends BaseOpenAIModelOptions {
endpoint?: string;
}

/**
* Options for configuring a model that calls and `OpenAI` compliant endpoint.
* @remarks
* The endpoint should comply with the OpenAPI spec for OpenAI's API:
*
* https://github.com/openai/openai-openapi
*
* And an example of a compliant endpoint is LLaMA.cpp's reference server:
*
* https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md
*
*/
export interface OpenAILikeModelOptions extends BaseOpenAIModelOptions {
/**
* Endpoint of the model server to call.
*/
endpoint: string;

/**
* Default model to use for completions.
*/
defaultModel: string;

/**
* Optional. API key to use when calling the models endpoint.
*/
apiKey?: string;
}

/**
* Options for configuring an `OpenAIModel` to call an Azure OpenAI hosted model.
*/
Expand Down Expand Up @@ -120,13 +164,13 @@ export class OpenAIModel implements PromptCompletionModel {
/**
* Options the client was configured with.
*/
public readonly options: OpenAIModelOptions | AzureOpenAIModelOptions;
public readonly options: OpenAIModelOptions | AzureOpenAIModelOptions | OpenAILikeModelOptions;

/**
* Creates a new `OpenAIModel` instance.
* @param {OpenAIModelOptions} options - Options for configuring the model client.
*/
public constructor(options: OpenAIModelOptions | AzureOpenAIModelOptions) {
public constructor(options: OpenAIModelOptions | AzureOpenAIModelOptions | OpenAILikeModelOptions) {
// Check for azure config
if ((options as AzureOpenAIModelOptions).azureApiKey) {
this._useAzure = true;
Expand Down Expand Up @@ -221,7 +265,7 @@ export class OpenAIModel implements PromptCompletionModel {
input = result.output[last];
}

// Call chat completion API
// Initialize chat completion request
const request: CreateChatCompletionRequest = this.copyOptionsToRequest<CreateChatCompletionRequest>(
{
messages: result.output as ChatCompletionRequestMessage[]
Expand All @@ -243,9 +287,17 @@ export class OpenAIModel implements PromptCompletionModel {
'user',
'functions',
'function_call',
'data_sources'
'data_sources',
]
);
if (this.options.responseFormat) {
request.response_format = this.options.responseFormat;
}
if (this.options.seed !== undefined) {
request.seed = this.options.seed;
}

// Call chat completion API
const response = await this.createChatCompletion(request, model);
if (this.options.logRequests) {
console.log(Colorize.title('CHAT RESPONSE:'));
Expand Down Expand Up @@ -346,7 +398,7 @@ export class OpenAIModel implements PromptCompletionModel {
if (this._useAzure) {
const options = this.options as AzureOpenAIModelOptions;
requestConfig.headers['api-key'] = options.azureApiKey;
} else {
} else if ((this.options as OpenAIModelOptions).apiKey) {
const options = this.options as OpenAIModelOptions;
requestConfig.headers['Authorization'] = `Bearer ${options.apiKey}`;
if (options.organization) {
Expand Down
2 changes: 1 addition & 1 deletion js/samples/01.getting-started/a.echoBot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"restify": "~11.1.0"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/node": "^20.12.7",
"@types/restify": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"restify": "~11.1.0"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/node": "^20.12.7",
"@types/restify": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"restify": "~11.1.0"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/node": "^20.12.7",
"@types/restify": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
2 changes: 1 addition & 1 deletion js/samples/03.ai-concepts/a.twentyQuestions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"restify": "~11.1.0"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/node": "^20.12.7",
"@types/restify": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"restify": "~11.1.0"
},
"devDependencies": {
"@types/node": "^20.12.2",
"@types/node": "^20.12.7",
"@types/restify": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
Loading

0 comments on commit 4a59b5d

Please sign in to comment.