@microsoft/teams.ai 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/citation.d.mts +19 -0
- package/dist/citation.d.ts +19 -0
- package/dist/citation.js +4 -0
- package/dist/citation.js.map +1 -0
- package/dist/citation.mjs +3 -0
- package/dist/citation.mjs.map +1 -0
- package/dist/function.d.mts +18 -0
- package/dist/function.d.ts +18 -0
- package/dist/function.js +4 -0
- package/dist/function.js.map +1 -0
- package/dist/function.mjs +3 -0
- package/dist/function.mjs.map +1 -0
- package/dist/index.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +12 -0
- package/dist/index.mjs.map +1 -0
- package/dist/local-memory.d.mts +32 -0
- package/dist/local-memory.d.ts +32 -0
- package/dist/local-memory.js +78 -0
- package/dist/local-memory.js.map +1 -0
- package/dist/local-memory.mjs +76 -0
- package/dist/local-memory.mjs.map +1 -0
- package/dist/memory.d.mts +11 -0
- package/dist/memory.d.ts +11 -0
- package/dist/memory.js +4 -0
- package/dist/memory.js.map +1 -0
- package/dist/memory.mjs +3 -0
- package/dist/memory.mjs.map +1 -0
- package/dist/message.d.mts +76 -0
- package/dist/message.d.ts +76 -0
- package/dist/message.js +4 -0
- package/dist/message.js.map +1 -0
- package/dist/message.mjs +3 -0
- package/dist/message.mjs.map +1 -0
- package/dist/models/audio.d.mts +27 -0
- package/dist/models/audio.d.ts +27 -0
- package/dist/models/audio.js +4 -0
- package/dist/models/audio.js.map +1 -0
- package/dist/models/audio.mjs +3 -0
- package/dist/models/audio.mjs.map +1 -0
- package/dist/models/chat.d.mts +46 -0
- package/dist/models/chat.d.ts +46 -0
- package/dist/models/chat.js +4 -0
- package/dist/models/chat.js.map +1 -0
- package/dist/models/chat.mjs +3 -0
- package/dist/models/chat.mjs.map +1 -0
- package/dist/models/image.d.mts +22 -0
- package/dist/models/image.d.ts +22 -0
- package/dist/models/image.js +4 -0
- package/dist/models/image.js.map +1 -0
- package/dist/models/image.mjs +3 -0
- package/dist/models/image.mjs.map +1 -0
- package/dist/models/index.d.mts +16 -0
- package/dist/models/index.d.ts +16 -0
- package/dist/models/index.js +28 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/index.mjs +5 -0
- package/dist/models/index.mjs.map +1 -0
- package/dist/prompts/audio.d.mts +54 -0
- package/dist/prompts/audio.d.ts +54 -0
- package/dist/prompts/audio.js +34 -0
- package/dist/prompts/audio.js.map +1 -0
- package/dist/prompts/audio.mjs +32 -0
- package/dist/prompts/audio.mjs.map +1 -0
- package/dist/prompts/chat.d.mts +146 -0
- package/dist/prompts/chat.d.ts +146 -0
- package/dist/prompts/chat.js +162 -0
- package/dist/prompts/chat.js.map +1 -0
- package/dist/prompts/chat.mjs +160 -0
- package/dist/prompts/chat.mjs.map +1 -0
- package/dist/prompts/index.d.mts +18 -0
- package/dist/prompts/index.d.ts +18 -0
- package/dist/prompts/index.js +21 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/index.mjs +4 -0
- package/dist/prompts/index.mjs.map +1 -0
- package/dist/prompts/plugin.d.mts +26 -0
- package/dist/prompts/plugin.d.ts +26 -0
- package/dist/prompts/plugin.js +4 -0
- package/dist/prompts/plugin.js.map +1 -0
- package/dist/prompts/plugin.mjs +3 -0
- package/dist/prompts/plugin.mjs.map +1 -0
- package/dist/schema.d.mts +46 -0
- package/dist/schema.d.ts +46 -0
- package/dist/schema.js +4 -0
- package/dist/schema.js.map +1 -0
- package/dist/schema.mjs +3 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/template.d.mts +13 -0
- package/dist/template.d.ts +13 -0
- package/dist/template.js +4 -0
- package/dist/template.js.map +1 -0
- package/dist/template.mjs +3 -0
- package/dist/template.mjs.map +1 -0
- package/dist/templates/index.d.mts +2 -0
- package/dist/templates/index.d.ts +2 -0
- package/dist/templates/index.js +14 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/index.mjs +3 -0
- package/dist/templates/index.mjs.map +1 -0
- package/dist/templates/string.d.mts +9 -0
- package/dist/templates/string.d.ts +9 -0
- package/dist/templates/string.js +14 -0
- package/dist/templates/string.js.map +1 -0
- package/dist/templates/string.mjs +12 -0
- package/dist/templates/string.mjs.map +1 -0
- package/dist/utils/types.d.mts +5 -0
- package/dist/utils/types.d.ts +5 -0
- package/dist/utils/types.js +4 -0
- package/dist/utils/types.js.map +1 -0
- package/dist/utils/types.mjs +3 -0
- package/dist/utils/types.mjs.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Teams: AI
|
|
2
|
+
|
|
3
|
+
<p>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@microsoft/teams.ai" target="_blank">
|
|
5
|
+
<img src="https://img.shields.io/npm/v/@microsoft/teams.ai" />
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@microsoft/teams.ai?activeTab=code" target="_blank">
|
|
8
|
+
<img src="https://img.shields.io/bundlephobia/min/@microsoft/teams.ai" />
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@microsoft/teams.ai?activeTab=dependencies" target="_blank">
|
|
11
|
+
<img src="https://img.shields.io/librariesio/release/npm/@microsoft/teams.ai" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@microsoft/teams.ai" target="_blank">
|
|
14
|
+
<img src="https://img.shields.io/npm/dw/@microsoft/teams.ai" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://microsoft.github.io/teams.js" target="_blank">
|
|
17
|
+
<img src="https://img.shields.io/badge/📖 docs-open-blue" />
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
AI tools/utilities.
|
|
22
|
+
|
|
23
|
+
<a href="https://microsoft.github.io/teams.js/2.getting-started/1.create-application.html" target="_blank">
|
|
24
|
+
<img src="https://img.shields.io/badge/📖 Getting Started-blue?style=for-the-badge" />
|
|
25
|
+
</a>
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$: npm install @microsoft/teams.ai
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Dependencies
|
|
34
|
+
|
|
35
|
+
N/A
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single instance of additional context information available when Azure OpenAI chat extensions are involved
|
|
3
|
+
* in the generation of a corresponding chat completions response. This context information is only populated when
|
|
4
|
+
* using an Azure OpenAI request configured to use a matching extension.
|
|
5
|
+
*/
|
|
6
|
+
type Citation = {
|
|
7
|
+
/** The content of the citation. */
|
|
8
|
+
content: string;
|
|
9
|
+
/** The title of the citation. */
|
|
10
|
+
title?: string;
|
|
11
|
+
/** The URL of the citation. */
|
|
12
|
+
url?: string;
|
|
13
|
+
/** The file path of the citation. */
|
|
14
|
+
filepath?: string;
|
|
15
|
+
/** The chunk ID of the citation. */
|
|
16
|
+
chunk_id?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type { Citation };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single instance of additional context information available when Azure OpenAI chat extensions are involved
|
|
3
|
+
* in the generation of a corresponding chat completions response. This context information is only populated when
|
|
4
|
+
* using an Azure OpenAI request configured to use a matching extension.
|
|
5
|
+
*/
|
|
6
|
+
type Citation = {
|
|
7
|
+
/** The content of the citation. */
|
|
8
|
+
content: string;
|
|
9
|
+
/** The title of the citation. */
|
|
10
|
+
title?: string;
|
|
11
|
+
/** The URL of the citation. */
|
|
12
|
+
url?: string;
|
|
13
|
+
/** The file path of the citation. */
|
|
14
|
+
filepath?: string;
|
|
15
|
+
/** The chunk ID of the citation. */
|
|
16
|
+
chunk_id?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type { Citation };
|
package/dist/citation.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"citation.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"citation.mjs"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Schema } from './schema.mjs';
|
|
2
|
+
|
|
3
|
+
type FunctionHandler<T = any> = (args: T) => any | Promise<any>;
|
|
4
|
+
type Function = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly parameters: Schema;
|
|
8
|
+
readonly handler: FunctionHandler;
|
|
9
|
+
};
|
|
10
|
+
type FunctionCall = {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly arguments: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type { Function, FunctionCall, FunctionHandler };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Schema } from './schema.js';
|
|
2
|
+
|
|
3
|
+
type FunctionHandler<T = any> = (args: T) => any | Promise<any>;
|
|
4
|
+
type Function = {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly description: string;
|
|
7
|
+
readonly parameters: Schema;
|
|
8
|
+
readonly handler: FunctionHandler;
|
|
9
|
+
};
|
|
10
|
+
type FunctionCall = {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly arguments: {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type { Function, FunctionCall, FunctionHandler };
|
package/dist/function.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"function.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"function.mjs"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { Citation } from './citation.mjs';
|
|
2
|
+
export { Function, FunctionCall, FunctionHandler } from './function.mjs';
|
|
3
|
+
export { LocalMemory, LocalMemoryOptions } from './local-memory.mjs';
|
|
4
|
+
export { IMemory } from './memory.mjs';
|
|
5
|
+
export { ContentPart, FunctionMessage, ImageContentPart, Message, MessageAudio, MessageContext, ModelMessage, SystemMessage, TextContentPart, UserMessage } from './message.mjs';
|
|
6
|
+
export { Model } from './models/index.mjs';
|
|
7
|
+
export { Prompt } from './prompts/index.mjs';
|
|
8
|
+
export { AnySchema, ArraySchema, BooleanSchema, NullSchema, NumberSchema, ObjectSchema, Schema, StringSchema } from './schema.mjs';
|
|
9
|
+
export { ITemplate } from './template.mjs';
|
|
10
|
+
export { StringTemplate } from './templates/string.mjs';
|
|
11
|
+
export { ChatSendOptions, IChatModel, TextChunkHandler } from './models/chat.mjs';
|
|
12
|
+
export { AudioToTextParams, IAudioModel, TextToAudioParams } from './models/audio.mjs';
|
|
13
|
+
export { IImageModel, TextToImageParams } from './models/image.mjs';
|
|
14
|
+
export { ChatPrompt, ChatPromptOptions, ChatPromptPlugin, ChatPromptSendOptions, IChatPrompt } from './prompts/chat.mjs';
|
|
15
|
+
export { AudioPrompt, AudioPromptOptions, IAudioPrompt } from './prompts/audio.mjs';
|
|
16
|
+
import '@microsoft/teams.common';
|
|
17
|
+
import './prompts/plugin.mjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { Citation } from './citation.js';
|
|
2
|
+
export { Function, FunctionCall, FunctionHandler } from './function.js';
|
|
3
|
+
export { LocalMemory, LocalMemoryOptions } from './local-memory.js';
|
|
4
|
+
export { IMemory } from './memory.js';
|
|
5
|
+
export { ContentPart, FunctionMessage, ImageContentPart, Message, MessageAudio, MessageContext, ModelMessage, SystemMessage, TextContentPart, UserMessage } from './message.js';
|
|
6
|
+
export { Model } from './models/index.js';
|
|
7
|
+
export { Prompt } from './prompts/index.js';
|
|
8
|
+
export { AnySchema, ArraySchema, BooleanSchema, NullSchema, NumberSchema, ObjectSchema, Schema, StringSchema } from './schema.js';
|
|
9
|
+
export { ITemplate } from './template.js';
|
|
10
|
+
export { StringTemplate } from './templates/string.js';
|
|
11
|
+
export { ChatSendOptions, IChatModel, TextChunkHandler } from './models/chat.js';
|
|
12
|
+
export { AudioToTextParams, IAudioModel, TextToAudioParams } from './models/audio.js';
|
|
13
|
+
export { IImageModel, TextToImageParams } from './models/image.js';
|
|
14
|
+
export { ChatPrompt, ChatPromptOptions, ChatPromptPlugin, ChatPromptSendOptions, IChatPrompt } from './prompts/chat.js';
|
|
15
|
+
export { AudioPrompt, AudioPromptOptions, IAudioPrompt } from './prompts/audio.js';
|
|
16
|
+
import '@microsoft/teams.common';
|
|
17
|
+
import './prompts/plugin.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var citation = require('./citation');
|
|
4
|
+
var _function = require('./function');
|
|
5
|
+
var localMemory = require('./local-memory');
|
|
6
|
+
var memory = require('./memory');
|
|
7
|
+
var message = require('./message');
|
|
8
|
+
var models = require('./models');
|
|
9
|
+
var prompts = require('./prompts');
|
|
10
|
+
var schema = require('./schema');
|
|
11
|
+
var template = require('./template');
|
|
12
|
+
var templates = require('./templates');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Object.keys(citation).forEach(function (k) {
|
|
17
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return citation[k]; }
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
Object.keys(_function).forEach(function (k) {
|
|
23
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return _function[k]; }
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
Object.keys(localMemory).forEach(function (k) {
|
|
29
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return localMemory[k]; }
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
Object.keys(memory).forEach(function (k) {
|
|
35
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return memory[k]; }
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
Object.keys(message).forEach(function (k) {
|
|
41
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return message[k]; }
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
Object.keys(models).forEach(function (k) {
|
|
47
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () { return models[k]; }
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
Object.keys(prompts).forEach(function (k) {
|
|
53
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () { return prompts[k]; }
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
Object.keys(schema).forEach(function (k) {
|
|
59
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () { return schema[k]; }
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
Object.keys(template).forEach(function (k) {
|
|
65
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () { return template[k]; }
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
Object.keys(templates).forEach(function (k) {
|
|
71
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return templates[k]; }
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './citation';
|
|
2
|
+
export * from './function';
|
|
3
|
+
export * from './local-memory';
|
|
4
|
+
export * from './memory';
|
|
5
|
+
export * from './message';
|
|
6
|
+
export * from './models';
|
|
7
|
+
export * from './prompts';
|
|
8
|
+
export * from './schema';
|
|
9
|
+
export * from './template';
|
|
10
|
+
export * from './templates';
|
|
11
|
+
//# sourceMappingURL=index.mjs.map
|
|
12
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs","sourcesContent":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Message, ModelMessage } from './message.mjs';
|
|
2
|
+
import { IMemory } from './memory.mjs';
|
|
3
|
+
import { IChatModel } from './models/chat.mjs';
|
|
4
|
+
import './citation.mjs';
|
|
5
|
+
import './function.mjs';
|
|
6
|
+
import './schema.mjs';
|
|
7
|
+
import '@microsoft/teams.common';
|
|
8
|
+
|
|
9
|
+
type LocalMemoryOptions = {
|
|
10
|
+
readonly max?: number;
|
|
11
|
+
readonly messages?: Message[];
|
|
12
|
+
readonly collapse?: {
|
|
13
|
+
readonly strategy: 'half' | 'full';
|
|
14
|
+
readonly model: IChatModel;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare class LocalMemory implements IMemory {
|
|
18
|
+
protected readonly messages: Message[];
|
|
19
|
+
protected readonly options: LocalMemoryOptions;
|
|
20
|
+
constructor(options?: LocalMemoryOptions);
|
|
21
|
+
get(i: number): Message | undefined;
|
|
22
|
+
set(i: number, message: Message): void;
|
|
23
|
+
delete(i: number): void;
|
|
24
|
+
push(message: Message): Promise<void>;
|
|
25
|
+
pop(): Message | undefined;
|
|
26
|
+
values(): Message[];
|
|
27
|
+
length(): number;
|
|
28
|
+
where(predicate: (value: Message, index: number) => boolean): Message[];
|
|
29
|
+
collapse(): Promise<ModelMessage | undefined>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { LocalMemory, type LocalMemoryOptions };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Message, ModelMessage } from './message.js';
|
|
2
|
+
import { IMemory } from './memory.js';
|
|
3
|
+
import { IChatModel } from './models/chat.js';
|
|
4
|
+
import './citation.js';
|
|
5
|
+
import './function.js';
|
|
6
|
+
import './schema.js';
|
|
7
|
+
import '@microsoft/teams.common';
|
|
8
|
+
|
|
9
|
+
type LocalMemoryOptions = {
|
|
10
|
+
readonly max?: number;
|
|
11
|
+
readonly messages?: Message[];
|
|
12
|
+
readonly collapse?: {
|
|
13
|
+
readonly strategy: 'half' | 'full';
|
|
14
|
+
readonly model: IChatModel;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare class LocalMemory implements IMemory {
|
|
18
|
+
protected readonly messages: Message[];
|
|
19
|
+
protected readonly options: LocalMemoryOptions;
|
|
20
|
+
constructor(options?: LocalMemoryOptions);
|
|
21
|
+
get(i: number): Message | undefined;
|
|
22
|
+
set(i: number, message: Message): void;
|
|
23
|
+
delete(i: number): void;
|
|
24
|
+
push(message: Message): Promise<void>;
|
|
25
|
+
pop(): Message | undefined;
|
|
26
|
+
values(): Message[];
|
|
27
|
+
length(): number;
|
|
28
|
+
where(predicate: (value: Message, index: number) => boolean): Message[];
|
|
29
|
+
collapse(): Promise<ModelMessage | undefined>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { LocalMemory, type LocalMemoryOptions };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class LocalMemory {
|
|
4
|
+
messages;
|
|
5
|
+
options;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.messages = options?.messages || [];
|
|
8
|
+
this.options = options || {};
|
|
9
|
+
}
|
|
10
|
+
get(i) {
|
|
11
|
+
if (i < 0 || i > this.messages.length - 1) return;
|
|
12
|
+
return this.messages[i];
|
|
13
|
+
}
|
|
14
|
+
set(i, message) {
|
|
15
|
+
if (i < 0 || i > this.messages.length - 1) return;
|
|
16
|
+
this.messages[i] = message;
|
|
17
|
+
}
|
|
18
|
+
delete(i) {
|
|
19
|
+
if (i < 0 || i > this.messages.length - 1) return;
|
|
20
|
+
this.messages.splice(i, 1);
|
|
21
|
+
}
|
|
22
|
+
async push(message) {
|
|
23
|
+
this.messages.push(message);
|
|
24
|
+
let len = this.length();
|
|
25
|
+
if (len === (this.options.max || 100)) {
|
|
26
|
+
await this.collapse();
|
|
27
|
+
len = this.length();
|
|
28
|
+
}
|
|
29
|
+
while (len > (this.options.max || 100) || this.messages[0].role === "model" && this.messages[0].function_calls?.length || this.messages[0].role === "function") {
|
|
30
|
+
const removed = this.pop();
|
|
31
|
+
if (!removed) break;
|
|
32
|
+
len = this.length();
|
|
33
|
+
if (len === 0) break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
pop() {
|
|
37
|
+
return this.messages.shift();
|
|
38
|
+
}
|
|
39
|
+
values() {
|
|
40
|
+
return this.messages.slice();
|
|
41
|
+
}
|
|
42
|
+
length() {
|
|
43
|
+
return this.messages.length;
|
|
44
|
+
}
|
|
45
|
+
where(predicate) {
|
|
46
|
+
return this.messages.filter(predicate);
|
|
47
|
+
}
|
|
48
|
+
async collapse() {
|
|
49
|
+
if (!this.options.collapse) return;
|
|
50
|
+
const start = 0;
|
|
51
|
+
let end = this.length() - 1;
|
|
52
|
+
if (this.options.collapse.strategy === "half") {
|
|
53
|
+
end = Math.floor(this.length() / 2) - 1;
|
|
54
|
+
}
|
|
55
|
+
let last = this.messages[end];
|
|
56
|
+
while (last.role === "model" && last.function_calls?.length || last.role === "function") {
|
|
57
|
+
end++;
|
|
58
|
+
last = this.messages[end];
|
|
59
|
+
}
|
|
60
|
+
const res = await this.options.collapse.model.send(
|
|
61
|
+
{
|
|
62
|
+
role: "user",
|
|
63
|
+
content: "summarize this conversation"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
messages: new LocalMemory({
|
|
67
|
+
messages: this.messages.slice(start, end + 1)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
this.messages.splice(start, end - start, res);
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.LocalMemory = LocalMemory;
|
|
77
|
+
//# sourceMappingURL=local-memory.js.map
|
|
78
|
+
//# sourceMappingURL=local-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/local-memory.ts"],"names":[],"mappings":";;AAaO,MAAM,WAA+B,CAAA;AAAA,EACvB,QAAA;AAAA,EACA,OAAA;AAAA,EAEnB,YAAY,OAA8B,EAAA;AACxC,IAAK,IAAA,CAAA,QAAA,GAAW,OAAS,EAAA,QAAA,IAAY,EAAC;AACtC,IAAK,IAAA,CAAA,OAAA,GAAU,WAAW,EAAC;AAAA;AAC7B,EAEA,IAAI,CAAW,EAAA;AACb,IAAA,IAAI,IAAI,CAAK,IAAA,CAAA,GAAI,IAAK,CAAA,QAAA,CAAS,SAAS,CAAG,EAAA;AAC3C,IAAO,OAAA,IAAA,CAAK,SAAS,CAAC,CAAA;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AAK,QAAS,CAAA,MAAA,CAAO,KAAO,EAAA,GAAA,GAAM,OAAO,GAAG,CAAA;AAC5C,IAAO,OAAA,GAAA;AAAA;AAEX","file":"local-memory.js","sourcesContent":["import { IMemory } from './memory';\nimport { Message } from './message';\nimport { IChatModel } from './models';\n\nexport type LocalMemoryOptions = {\n readonly max?: number;\n readonly messages?: Message[];\n readonly collapse?: {\n readonly strategy: 'half' | 'full';\n readonly model: IChatModel;\n };\n};\n\nexport class LocalMemory implements IMemory {\n protected readonly messages: Message[];\n protected readonly options: LocalMemoryOptions;\n\n constructor(options?: LocalMemoryOptions) {\n this.messages = options?.messages || [];\n this.options = options || {};\n }\n\n get(i: number) {\n if (i < 0 || i > this.messages.length - 1) return;\n return this.messages[i];\n }\n\n set(i: number, message: Message) {\n if (i < 0 || i > this.messages.length - 1) return;\n this.messages[i] = message;\n }\n\n delete(i: number) {\n if (i < 0 || i > this.messages.length - 1) return;\n this.messages.splice(i, 1);\n }\n\n async push(message: Message) {\n this.messages.push(message);\n let len = this.length();\n\n if (len === (this.options.max || 100)) {\n await this.collapse();\n len = this.length();\n }\n\n while (\n len > (this.options.max || 100) ||\n (this.messages[0].role === 'model' && this.messages[0].function_calls?.length) ||\n this.messages[0].role === 'function'\n ) {\n const removed = this.pop();\n\n if (!removed) break;\n\n len = this.length();\n\n if (len === 0) break;\n }\n }\n\n pop() {\n return this.messages.shift();\n }\n\n values() {\n return this.messages.slice();\n }\n\n length() {\n return this.messages.length;\n }\n\n where(predicate: (value: Message, index: number) => boolean) {\n return this.messages.filter(predicate);\n }\n\n async collapse() {\n if (!this.options.collapse) return;\n\n const start = 0;\n let end = this.length() - 1;\n\n if (this.options.collapse.strategy === 'half') {\n end = Math.floor(this.length() / 2) - 1;\n }\n\n let last = this.messages[end];\n\n while ((last.role === 'model' && last.function_calls?.length) || last.role === 'function') {\n end++;\n last = this.messages[end];\n }\n\n const res = await this.options.collapse.model.send(\n {\n role: 'user',\n content: 'summarize this conversation',\n },\n {\n messages: new LocalMemory({\n messages: this.messages.slice(start, end + 1),\n }),\n }\n );\n\n this.messages.splice(start, end - start, res);\n return res;\n }\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
class LocalMemory {
|
|
2
|
+
messages;
|
|
3
|
+
options;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
this.messages = options?.messages || [];
|
|
6
|
+
this.options = options || {};
|
|
7
|
+
}
|
|
8
|
+
get(i) {
|
|
9
|
+
if (i < 0 || i > this.messages.length - 1) return;
|
|
10
|
+
return this.messages[i];
|
|
11
|
+
}
|
|
12
|
+
set(i, message) {
|
|
13
|
+
if (i < 0 || i > this.messages.length - 1) return;
|
|
14
|
+
this.messages[i] = message;
|
|
15
|
+
}
|
|
16
|
+
delete(i) {
|
|
17
|
+
if (i < 0 || i > this.messages.length - 1) return;
|
|
18
|
+
this.messages.splice(i, 1);
|
|
19
|
+
}
|
|
20
|
+
async push(message) {
|
|
21
|
+
this.messages.push(message);
|
|
22
|
+
let len = this.length();
|
|
23
|
+
if (len === (this.options.max || 100)) {
|
|
24
|
+
await this.collapse();
|
|
25
|
+
len = this.length();
|
|
26
|
+
}
|
|
27
|
+
while (len > (this.options.max || 100) || this.messages[0].role === "model" && this.messages[0].function_calls?.length || this.messages[0].role === "function") {
|
|
28
|
+
const removed = this.pop();
|
|
29
|
+
if (!removed) break;
|
|
30
|
+
len = this.length();
|
|
31
|
+
if (len === 0) break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
pop() {
|
|
35
|
+
return this.messages.shift();
|
|
36
|
+
}
|
|
37
|
+
values() {
|
|
38
|
+
return this.messages.slice();
|
|
39
|
+
}
|
|
40
|
+
length() {
|
|
41
|
+
return this.messages.length;
|
|
42
|
+
}
|
|
43
|
+
where(predicate) {
|
|
44
|
+
return this.messages.filter(predicate);
|
|
45
|
+
}
|
|
46
|
+
async collapse() {
|
|
47
|
+
if (!this.options.collapse) return;
|
|
48
|
+
const start = 0;
|
|
49
|
+
let end = this.length() - 1;
|
|
50
|
+
if (this.options.collapse.strategy === "half") {
|
|
51
|
+
end = Math.floor(this.length() / 2) - 1;
|
|
52
|
+
}
|
|
53
|
+
let last = this.messages[end];
|
|
54
|
+
while (last.role === "model" && last.function_calls?.length || last.role === "function") {
|
|
55
|
+
end++;
|
|
56
|
+
last = this.messages[end];
|
|
57
|
+
}
|
|
58
|
+
const res = await this.options.collapse.model.send(
|
|
59
|
+
{
|
|
60
|
+
role: "user",
|
|
61
|
+
content: "summarize this conversation"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
messages: new LocalMemory({
|
|
65
|
+
messages: this.messages.slice(start, end + 1)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
this.messages.splice(start, end - start, res);
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { LocalMemory };
|
|
75
|
+
//# sourceMappingURL=local-memory.mjs.map
|
|
76
|
+
//# sourceMappingURL=local-memory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/local-memory.ts"],"names":[],"mappings":"AAaO,MAAM,WAA+B,CAAA;AAAA,EACvB,QAAA;AAAA,EACA,OAAA;AAAA,EAEnB,YAAY,OAA8B,EAAA;AACxC,IAAK,IAAA,CAAA,QAAA,GAAW,OAAS,EAAA,QAAA,IAAY,EAAC;AACtC,IAAK,IAAA,CAAA,OAAA,GAAU,WAAW,EAAC;AAAA;AAC7B,EAEA,IAAI,CAAW,EAAA;AACb,IAAA,IAAI,IAAI,CAAK,IAAA,CAAA,GAAI,IAAK,CAAA,QAAA,CAAS,SAAS,CAAG,EAAA;AAC3C,IAAO,OAAA,IAAA,CAAK,SAAS,CAAC,CAAA;AAAA;AACxB,EAEA,GAAA,CAAI,GAAW,OAAkB,EAAA;AAC/B,IAAA,IAAI,IAAI,CAAK,IAAA,CAAA,GAAI,IAAK,CAAA,QAAA,CAAS,S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ourcesContent":["import { IMemory } from './memory';\nimport { Message } from './message';\nimport { IChatModel } from './models';\n\nexport type LocalMemoryOptions = {\n readonly max?: number;\n readonly messages?: Message[];\n readonly collapse?: {\n readonly strategy: 'half' | 'full';\n readonly model: IChatModel;\n };\n};\n\nexport class LocalMemory implements IMemory {\n protected readonly messages: Message[];\n protected readonly options: LocalMemoryOptions;\n\n constructor(options?: LocalMemoryOptions) {\n this.messages = options?.messages || [];\n this.options = options || {};\n }\n\n get(i: number) {\n if (i < 0 || i > this.messages.length - 1) return;\n return this.messages[i];\n }\n\n set(i: number, message: Message) {\n if (i < 0 || i > this.messages.length - 1) return;\n this.messages[i] = message;\n }\n\n delete(i: number) {\n if (i < 0 || i > this.messages.length - 1) return;\n this.messages.splice(i, 1);\n }\n\n async push(message: Message) {\n this.messages.push(message);\n let len = this.length();\n\n if (len === (this.options.max || 100)) {\n await this.collapse();\n len = this.length();\n }\n\n while (\n len > (this.options.max || 100) ||\n (this.messages[0].role === 'model' && this.messages[0].function_calls?.length) ||\n this.messages[0].role === 'function'\n ) {\n const removed = this.pop();\n\n if (!removed) break;\n\n len = this.length();\n\n if (len === 0) break;\n }\n }\n\n pop() {\n return this.messages.shift();\n }\n\n values() {\n return this.messages.slice();\n }\n\n length() {\n return this.messages.length;\n }\n\n where(predicate: (value: Message, index: number) => boolean) {\n return this.messages.filter(predicate);\n }\n\n async collapse() {\n if (!this.options.collapse) return;\n\n const start = 0;\n let end = this.length() - 1;\n\n if (this.options.collapse.strategy === 'half') {\n end = Math.floor(this.length() / 2) - 1;\n }\n\n let last = this.messages[end];\n\n while ((last.role === 'model' && last.function_calls?.length) || last.role === 'function') {\n end++;\n last = this.messages[end];\n }\n\n const res = await this.options.collapse.model.send(\n {\n role: 'user',\n content: 'summarize this conversation',\n },\n {\n messages: new LocalMemory({\n messages: this.messages.slice(start, end + 1),\n }),\n }\n );\n\n this.messages.splice(start, end - start, res);\n return res;\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IListStorage } from '@microsoft/teams.common';
|
|
2
|
+
import { Message } from './message.mjs';
|
|
3
|
+
import './citation.mjs';
|
|
4
|
+
import './function.mjs';
|
|
5
|
+
import './schema.mjs';
|
|
6
|
+
|
|
7
|
+
interface IMemory extends IListStorage<Message> {
|
|
8
|
+
collapse(): (Message | undefined) | Promise<Message | undefined>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type { IMemory };
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IListStorage } from '@microsoft/teams.common';
|
|
2
|
+
import { Message } from './message.js';
|
|
3
|
+
import './citation.js';
|
|
4
|
+
import './function.js';
|
|
5
|
+
import './schema.js';
|
|
6
|
+
|
|
7
|
+
interface IMemory extends IListStorage<Message> {
|
|
8
|
+
collapse(): (Message | undefined) | Promise<Message | undefined>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type { IMemory };
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"memory.js"}
|
package/dist/memory.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"memory.mjs"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Citation } from './citation.mjs';
|
|
2
|
+
import { FunctionCall } from './function.mjs';
|
|
3
|
+
import './schema.mjs';
|
|
4
|
+
|
|
5
|
+
type Message = UserMessage | ModelMessage | SystemMessage | FunctionMessage;
|
|
6
|
+
type UserMessage = {
|
|
7
|
+
role: 'user';
|
|
8
|
+
content: string | ContentPart[];
|
|
9
|
+
};
|
|
10
|
+
type ModelMessage = {
|
|
11
|
+
role: 'model';
|
|
12
|
+
audio?: MessageAudio;
|
|
13
|
+
content?: string;
|
|
14
|
+
context?: MessageContext;
|
|
15
|
+
function_calls?: FunctionCall[];
|
|
16
|
+
};
|
|
17
|
+
type SystemMessage = {
|
|
18
|
+
role: 'system';
|
|
19
|
+
content: string;
|
|
20
|
+
};
|
|
21
|
+
type FunctionMessage = {
|
|
22
|
+
role: 'function';
|
|
23
|
+
content?: string;
|
|
24
|
+
function_id: string;
|
|
25
|
+
};
|
|
26
|
+
type ContentPart = TextContentPart | ImageContentPart;
|
|
27
|
+
type TextContentPart = {
|
|
28
|
+
type: 'text';
|
|
29
|
+
text: string;
|
|
30
|
+
};
|
|
31
|
+
type ImageContentPart = {
|
|
32
|
+
type: 'image_url';
|
|
33
|
+
image_url: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A representation of the additional context information available when Azure OpenAI chat extensions are involved
|
|
37
|
+
* in the generation of a corresponding chat completions response. This context information is only populated when
|
|
38
|
+
* using an Azure OpenAI request configured to use a matching extension.
|
|
39
|
+
*/
|
|
40
|
+
type MessageContext = {
|
|
41
|
+
/**
|
|
42
|
+
* The contextual information associated with the Azure chat extensions used for a chat completions request.
|
|
43
|
+
* These messages describe the data source retrievals, plugin invocations, and other intermediate steps taken in the
|
|
44
|
+
* course of generating a chat completions response that was augmented by capabilities from Azure OpenAI chat
|
|
45
|
+
* extensions.
|
|
46
|
+
*/
|
|
47
|
+
citations?: Array<Citation>;
|
|
48
|
+
/** The detected intent from the chat history, used to pass to the next turn to carry over the context. */
|
|
49
|
+
intent?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* If the audio output modality is requested, this object contains data about the
|
|
53
|
+
* audio response from the model.
|
|
54
|
+
*/
|
|
55
|
+
type MessageAudio = {
|
|
56
|
+
/**
|
|
57
|
+
* Unique identifier for this audio response.
|
|
58
|
+
*/
|
|
59
|
+
id: string;
|
|
60
|
+
/**
|
|
61
|
+
* Base64 encoded audio bytes generated by the model, in the format specified in
|
|
62
|
+
* the request.
|
|
63
|
+
*/
|
|
64
|
+
data: string;
|
|
65
|
+
/**
|
|
66
|
+
* The Unix timestamp (in seconds) for when this audio response will no longer be
|
|
67
|
+
* accessible on the server for use in multi-turn conversations.
|
|
68
|
+
*/
|
|
69
|
+
expires_at: number;
|
|
70
|
+
/**
|
|
71
|
+
* Transcript of the audio generated by the model.
|
|
72
|
+
*/
|
|
73
|
+
transcript: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export type { ContentPart, FunctionMessage, ImageContentPart, Message, MessageAudio, MessageContext, ModelMessage, SystemMessage, TextContentPart, UserMessage };
|