@modular-prompt/process 0.1.11
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/LICENSE +21 -0
- package/README.md +166 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/dialogue.d.ts +39 -0
- package/dist/modules/dialogue.d.ts.map +1 -0
- package/dist/modules/dialogue.js +106 -0
- package/dist/modules/dialogue.js.map +1 -0
- package/dist/modules/index.d.ts +9 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +5 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/material.d.ts +21 -0
- package/dist/modules/material.d.ts.map +1 -0
- package/dist/modules/material.js +41 -0
- package/dist/modules/material.js.map +1 -0
- package/dist/modules/stream-processing.d.ts +26 -0
- package/dist/modules/stream-processing.d.ts.map +1 -0
- package/dist/modules/stream-processing.js +128 -0
- package/dist/modules/stream-processing.js.map +1 -0
- package/dist/modules/summarize.d.ts +32 -0
- package/dist/modules/summarize.d.ts.map +1 -0
- package/dist/modules/summarize.js +97 -0
- package/dist/modules/summarize.js.map +1 -0
- package/dist/workflows/agent-workflow.d.ts +55 -0
- package/dist/workflows/agent-workflow.d.ts.map +1 -0
- package/dist/workflows/agent-workflow.js +337 -0
- package/dist/workflows/agent-workflow.js.map +1 -0
- package/dist/workflows/agentic-workflow/agentic-workflow.d.ts +13 -0
- package/dist/workflows/agentic-workflow/agentic-workflow.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/agentic-workflow.js +235 -0
- package/dist/workflows/agentic-workflow/agentic-workflow.js.map +1 -0
- package/dist/workflows/agentic-workflow/index.d.ts +4 -0
- package/dist/workflows/agentic-workflow/index.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/index.js +5 -0
- package/dist/workflows/agentic-workflow/index.js.map +1 -0
- package/dist/workflows/agentic-workflow/modules/agentic.d.ts +12 -0
- package/dist/workflows/agentic-workflow/modules/agentic.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/modules/agentic.js +22 -0
- package/dist/workflows/agentic-workflow/modules/agentic.js.map +1 -0
- package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts +15 -0
- package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/modules/execution-freeform.js +140 -0
- package/dist/workflows/agentic-workflow/modules/execution-freeform.js.map +1 -0
- package/dist/workflows/agentic-workflow/modules/execution.d.ts +11 -0
- package/dist/workflows/agentic-workflow/modules/execution.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/modules/execution.js +180 -0
- package/dist/workflows/agentic-workflow/modules/execution.js.map +1 -0
- package/dist/workflows/agentic-workflow/modules/index.d.ts +6 -0
- package/dist/workflows/agentic-workflow/modules/index.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/modules/index.js +7 -0
- package/dist/workflows/agentic-workflow/modules/index.js.map +1 -0
- package/dist/workflows/agentic-workflow/modules/integration.d.ts +11 -0
- package/dist/workflows/agentic-workflow/modules/integration.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/modules/integration.js +85 -0
- package/dist/workflows/agentic-workflow/modules/integration.js.map +1 -0
- package/dist/workflows/agentic-workflow/modules/planning.d.ts +11 -0
- package/dist/workflows/agentic-workflow/modules/planning.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/modules/planning.js +103 -0
- package/dist/workflows/agentic-workflow/modules/planning.js.map +1 -0
- package/dist/workflows/agentic-workflow/types.d.ts +60 -0
- package/dist/workflows/agentic-workflow/types.d.ts.map +1 -0
- package/dist/workflows/agentic-workflow/types.js +2 -0
- package/dist/workflows/agentic-workflow/types.js.map +1 -0
- package/dist/workflows/concat-process-workflow.d.ts +29 -0
- package/dist/workflows/concat-process-workflow.d.ts.map +1 -0
- package/dist/workflows/concat-process-workflow.js +121 -0
- package/dist/workflows/concat-process-workflow.js.map +1 -0
- package/dist/workflows/dialogue-workflow.d.ts +25 -0
- package/dist/workflows/dialogue-workflow.d.ts.map +1 -0
- package/dist/workflows/dialogue-workflow.js +139 -0
- package/dist/workflows/dialogue-workflow.js.map +1 -0
- package/dist/workflows/index.d.ts +14 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +13 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/self-prompting-workflow/index.d.ts +12 -0
- package/dist/workflows/self-prompting-workflow/index.d.ts.map +1 -0
- package/dist/workflows/self-prompting-workflow/index.js +11 -0
- package/dist/workflows/self-prompting-workflow/index.js.map +1 -0
- package/dist/workflows/self-prompting-workflow/modules/integration.d.ts +11 -0
- package/dist/workflows/self-prompting-workflow/modules/integration.d.ts.map +1 -0
- package/dist/workflows/self-prompting-workflow/modules/integration.js +82 -0
- package/dist/workflows/self-prompting-workflow/modules/integration.js.map +1 -0
- package/dist/workflows/self-prompting-workflow/modules/planning.d.ts +11 -0
- package/dist/workflows/self-prompting-workflow/modules/planning.d.ts.map +1 -0
- package/dist/workflows/self-prompting-workflow/modules/planning.js +108 -0
- package/dist/workflows/self-prompting-workflow/modules/planning.js.map +1 -0
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts +14 -0
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts.map +1 -0
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js +250 -0
- package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js.map +1 -0
- package/dist/workflows/self-prompting-workflow/types.d.ts +56 -0
- package/dist/workflows/self-prompting-workflow/types.d.ts.map +1 -0
- package/dist/workflows/self-prompting-workflow/types.js +2 -0
- package/dist/workflows/self-prompting-workflow/types.js.map +1 -0
- package/dist/workflows/stream-workflow.d.ts +17 -0
- package/dist/workflows/stream-workflow.d.ts.map +1 -0
- package/dist/workflows/stream-workflow.js +119 -0
- package/dist/workflows/stream-workflow.js.map +1 -0
- package/dist/workflows/summarize-workflow.d.ts +39 -0
- package/dist/workflows/summarize-workflow.d.ts.map +1 -0
- package/dist/workflows/summarize-workflow.js +152 -0
- package/dist/workflows/summarize-workflow.js.map +1 -0
- package/dist/workflows/types.d.ts +37 -0
- package/dist/workflows/types.d.ts.map +1 -0
- package/dist/workflows/types.js +25 -0
- package/dist/workflows/types.js.map +1 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 otolab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# @modular-prompt/process
|
|
2
|
+
|
|
3
|
+
プロンプトモジュールとワークフローを提供するパッケージ。
|
|
4
|
+
|
|
5
|
+
## インストール
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @modular-prompt/process
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## ワークフロー
|
|
12
|
+
|
|
13
|
+
### チャンク処理ワークフロー
|
|
14
|
+
|
|
15
|
+
- **`streamProcess`** - ステートを保持しながらチャンクを逐次処理
|
|
16
|
+
- **`concatProcess`** - 各チャンクを独立して処理し、結果を結合
|
|
17
|
+
|
|
18
|
+
### エージェント型ワークフロー
|
|
19
|
+
|
|
20
|
+
- **`agenticProcess`** - 自律的な複数ステップ処理(計画→実行→統合)
|
|
21
|
+
- **`agentProcess`** - シンプルな計画→実行→統合ワークフロー
|
|
22
|
+
|
|
23
|
+
## モジュール
|
|
24
|
+
|
|
25
|
+
- **`streamProcessing`** - チャンク単位の逐次処理と状態管理
|
|
26
|
+
- **`withMaterials`** - 資料をプロンプトに含める
|
|
27
|
+
- **`dialogueモジュール群`** - 対話処理用モジュール
|
|
28
|
+
- **`summarizeモジュール群`** - 要約処理用モジュール
|
|
29
|
+
- **`agenticモジュール群`** - エージェント型ワークフロー用モジュール
|
|
30
|
+
|
|
31
|
+
## 使用例
|
|
32
|
+
|
|
33
|
+
### チャンク処理
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { streamProcess } from '@modular-prompt/process';
|
|
37
|
+
import { streamProcessing } from '@modular-prompt/process';
|
|
38
|
+
import { TestDriver } from '@modular-prompt/driver';
|
|
39
|
+
|
|
40
|
+
const driver = new TestDriver(['response1', 'response2']);
|
|
41
|
+
|
|
42
|
+
const result = await streamProcess(
|
|
43
|
+
driver,
|
|
44
|
+
streamProcessing,
|
|
45
|
+
{
|
|
46
|
+
chunks: [{ content: 'text1' }, { content: 'text2' }],
|
|
47
|
+
state: { content: '', usage: 0 }
|
|
48
|
+
},
|
|
49
|
+
{ tokenLimit: 1000 }
|
|
50
|
+
);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### エージェント型ワークフロー
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { agenticProcess } from '@modular-prompt/process';
|
|
57
|
+
import { AnthropicDriver } from '@modular-prompt/driver';
|
|
58
|
+
|
|
59
|
+
const driver = new AnthropicDriver({
|
|
60
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
61
|
+
model: 'claude-3-5-sonnet-20241022'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ユーザー定義のプロンプトモジュール
|
|
65
|
+
const userModule = {
|
|
66
|
+
objective: ['今日の夕飯の献立を決定する'],
|
|
67
|
+
instructions: [
|
|
68
|
+
'- 冷蔵庫の材料から作れる主菜候補を検討する',
|
|
69
|
+
'- 過去の献立と比較し、似たものが続かないようにする',
|
|
70
|
+
'- 選んだ主菜に合う副菜を提案する',
|
|
71
|
+
'- 不足している材料があれば買い出しリストを作成する'
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// コンテキスト(初期データ)
|
|
76
|
+
const context = {
|
|
77
|
+
objective: '今日の夕飯の献立を決定する',
|
|
78
|
+
inputs: {
|
|
79
|
+
refrigerator: {
|
|
80
|
+
proteins: ['鶏もも肉 300g', '豚バラ肉 200g', '卵 6個'],
|
|
81
|
+
vegetables: ['キャベツ', '人参', '玉ねぎ', 'じゃがいも']
|
|
82
|
+
},
|
|
83
|
+
pastMeals: [
|
|
84
|
+
{ date: '昨日', mainDish: 'カレーライス' },
|
|
85
|
+
{ date: '一昨日', mainDish: '生姜焼き' }
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// ワークフロー実行(計画→実行→統合)
|
|
91
|
+
const result = await agenticProcess(driver, userModule, context, {
|
|
92
|
+
maxSteps: 5 // 最大5ステップまで
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
console.log(result.output); // 最終的な献立提案
|
|
96
|
+
console.log(result.metadata); // { planSteps: 5, executedSteps: 5, actionsUsed: 0 }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 簡易エージェントワークフロー
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { agentProcess } from '@modular-prompt/process';
|
|
103
|
+
import { TestDriver } from '@modular-prompt/driver';
|
|
104
|
+
|
|
105
|
+
const driver = new TestDriver();
|
|
106
|
+
|
|
107
|
+
const userModule = {
|
|
108
|
+
objective: ['週末旅行プランを提案する'],
|
|
109
|
+
instructions: [
|
|
110
|
+
'- 交通手段・宿泊先・食事プランを検討する',
|
|
111
|
+
'- 入力データに応じて実行計画を自律的に組み立てる'
|
|
112
|
+
]
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const context = {
|
|
116
|
+
objective: '週末旅行プランを提案する',
|
|
117
|
+
inputs: {
|
|
118
|
+
budget: '50,000円',
|
|
119
|
+
city: '箱根'
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const actions = {
|
|
124
|
+
lookupHotel: async (params: { city: string }) => {
|
|
125
|
+
return { recommended: [`${params.city} 温泉旅館`] };
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const result = await agentProcess(driver, userModule, context, {
|
|
130
|
+
maxSteps: 4,
|
|
131
|
+
actions
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
console.log(result.output);
|
|
135
|
+
console.log(result.metadata); // { planSteps: 3, executedSteps: 3, actionsUsed: 1 }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### アクション(外部ツール)の使用
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { agenticProcess } from '@modular-prompt/process';
|
|
142
|
+
|
|
143
|
+
// 外部ツール/APIの定義
|
|
144
|
+
const actions = {
|
|
145
|
+
fetchWeather: async (params: { location: string }) => {
|
|
146
|
+
const response = await fetch(`https://api.weather.com/${params.location}`);
|
|
147
|
+
return response.json();
|
|
148
|
+
},
|
|
149
|
+
searchRecipes: async (params: { ingredients: string[] }) => {
|
|
150
|
+
// レシピ検索APIを呼び出し
|
|
151
|
+
return { recipes: [...] };
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const result = await agenticProcess(driver, userModule, context, {
|
|
156
|
+
maxSteps: 5,
|
|
157
|
+
actions // アクションを渡す
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// AIが計画フェーズで必要なアクションを判断し、実行フェーズで自動的に呼び出す
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
## ライセンス
|
|
165
|
+
|
|
166
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAC;AAGnC,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,cAAc,oBAAoB,CAAC;AAEnC,sBAAsB;AACtB,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PromptModule } from '@modular-prompt/core';
|
|
2
|
+
/**
|
|
3
|
+
* Context for dialogue modules
|
|
4
|
+
*/
|
|
5
|
+
export interface DialogueContext {
|
|
6
|
+
messages?: Array<{
|
|
7
|
+
content: string;
|
|
8
|
+
role: 'system' | 'assistant' | 'user';
|
|
9
|
+
name?: string;
|
|
10
|
+
}>;
|
|
11
|
+
state?: {
|
|
12
|
+
content: string;
|
|
13
|
+
usage?: number;
|
|
14
|
+
};
|
|
15
|
+
preparationNote?: {
|
|
16
|
+
content: string;
|
|
17
|
+
};
|
|
18
|
+
range?: {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base dialogue module - defines dialogue environment and basic conversation rules
|
|
25
|
+
*/
|
|
26
|
+
export declare const dialogueBase: PromptModule<DialogueContext>;
|
|
27
|
+
/**
|
|
28
|
+
* First pass of two-pass response - creates Response Preparation Notes
|
|
29
|
+
*/
|
|
30
|
+
export declare const firstOfTwoPassResponse: PromptModule<DialogueContext>;
|
|
31
|
+
/**
|
|
32
|
+
* Second pass of two-pass response - creates the Response Statement
|
|
33
|
+
*/
|
|
34
|
+
export declare const secondOfTwoPassResponse: PromptModule<DialogueContext>;
|
|
35
|
+
/**
|
|
36
|
+
* Module for maintaining conversation state
|
|
37
|
+
*/
|
|
38
|
+
export declare const withTalkState: PromptModule<DialogueContext>;
|
|
39
|
+
//# sourceMappingURL=dialogue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialogue.d.ts","sourceRoot":"","sources":["../../src/modules/dialogue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAqC,MAAM,sBAAsB,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;QACtC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IACH,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,eAAe,CAAC,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,eAAe,CA0BtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,YAAY,CAAC,eAAe,CAkChE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,YAAY,CAAC,eAAe,CAwBjE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,eAAe,CAcvD,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base dialogue module - defines dialogue environment and basic conversation rules
|
|
3
|
+
*/
|
|
4
|
+
export const dialogueBase = {
|
|
5
|
+
objective: [
|
|
6
|
+
'You are the main assistant of the dialogue system, and your name is Nano.'
|
|
7
|
+
],
|
|
8
|
+
terms: [
|
|
9
|
+
'Dialogue Environment: The environment in which the user and the assistants are interacting, as defined by the current prompt, including the Dialogue Theme, the set of materials, and a history or summary of the conversation.',
|
|
10
|
+
'Messages: These are the logs of messages from the user, assistant, and system. They are arranged in chronological order, with the most recent message at the end. The entire exchange of messages forms one context.'
|
|
11
|
+
],
|
|
12
|
+
messages: [
|
|
13
|
+
(context) => {
|
|
14
|
+
if (!context.messages)
|
|
15
|
+
return null;
|
|
16
|
+
const messages = context.range
|
|
17
|
+
? context.messages.slice(context.range.start, context.range.end)
|
|
18
|
+
: context.messages;
|
|
19
|
+
return messages.map(msg => ({
|
|
20
|
+
type: 'message',
|
|
21
|
+
content: msg.content,
|
|
22
|
+
role: msg.role,
|
|
23
|
+
name: msg.name
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* First pass of two-pass response - creates Response Preparation Notes
|
|
30
|
+
*/
|
|
31
|
+
export const firstOfTwoPassResponse = {
|
|
32
|
+
objective: [
|
|
33
|
+
"Assistant's task is to create responses in a two-pass process. The first pass is to create the Response Preparation Notes filled with sufficient information.",
|
|
34
|
+
'Note that at this stage, which is a non-interactive stage, we are not yet creating the final Response Statement text.'
|
|
35
|
+
],
|
|
36
|
+
terms: [
|
|
37
|
+
"Response Preparation Notes: This is a document created during the initial phase of preparing a response to the user's message. It's not a prompt, nor the response statement itself, but a detailed record of the analysis conducted in accordance with the provided instructions. It serves as a roadmap for crafting the final response statement.",
|
|
38
|
+
'Response Statement: A response provided to the user. It is crafted with reference to the Response Preparation Notes, which are created in the preliminary stage of formulating the response statement.'
|
|
39
|
+
],
|
|
40
|
+
instructions: [
|
|
41
|
+
'Start by thoroughly reading the exchange of messages to understand the overall topic and context. Summarize it concisely.',
|
|
42
|
+
"Next, focus on the user's most recent message. Conduct a detailed analysis of the implicit context and what the pronouns refer to. Interpret the user's request and elaborate on their intent. Look for any unresolved requests or questions.",
|
|
43
|
+
'Then, make a judgment on what you should do and set a goal. Look for what can be done in response to it.',
|
|
44
|
+
'Finally, compile the information necessary to create a response to the user.'
|
|
45
|
+
],
|
|
46
|
+
guidelines: [
|
|
47
|
+
'Since the note is a text for the Assistant to read, "you" should refer to the Assistant.',
|
|
48
|
+
'Remember that there are three roles of speakers in the dialogue environment: user, assistant, and system. Each statement should be interpreted separately.',
|
|
49
|
+
"The key part of the Response Preparation Notes is understanding the user's question intent. Make sure to quote the user's message that needs to be responded to and create explanations for any pronouns or parts that implicitly refer to something.",
|
|
50
|
+
"Based on the user's most recent message complexity, indicate in your Response Preparation Notes whether a concise or detailed response should be prepared."
|
|
51
|
+
],
|
|
52
|
+
cue: [
|
|
53
|
+
'The required output at this stage is the content of the Response Preparation Notes. As this is the first stage of the 2-pass process, do not output the response statement.',
|
|
54
|
+
{
|
|
55
|
+
type: 'subsection',
|
|
56
|
+
content: '',
|
|
57
|
+
title: 'Response Preparation Notes',
|
|
58
|
+
items: ['']
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Second pass of two-pass response - creates the Response Statement
|
|
64
|
+
*/
|
|
65
|
+
export const secondOfTwoPassResponse = {
|
|
66
|
+
objective: [
|
|
67
|
+
'Your task is to create responses in a two-pass process. The second pass is to create the Response Statement, referencing but not including the content of the Response Preparation Notes.'
|
|
68
|
+
],
|
|
69
|
+
terms: [
|
|
70
|
+
'Response Statement: A response statement to the user.',
|
|
71
|
+
"Response Preparation Note: The initial output of the first pass in the two-pass process of creating responses. They are a detailed analysis and interpretation of the user's most recent message, including the implicit context and what the pronouns refer to. The purpose of these notes is to prepare for the creation of the Response Statement."
|
|
72
|
+
],
|
|
73
|
+
instructions: [
|
|
74
|
+
'Consider the Response Preparation Notes as a special part of the dialogue environment. Use them, along with the rest of the dialogue environment, to create a response statement.',
|
|
75
|
+
'The output should be the response statement only.'
|
|
76
|
+
],
|
|
77
|
+
preparationNote: [
|
|
78
|
+
(context) => {
|
|
79
|
+
if (!context.preparationNote?.content)
|
|
80
|
+
return null;
|
|
81
|
+
return {
|
|
82
|
+
type: 'text',
|
|
83
|
+
content: context.preparationNote.content
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Module for maintaining conversation state
|
|
90
|
+
*/
|
|
91
|
+
export const withTalkState = {
|
|
92
|
+
terms: [
|
|
93
|
+
'Current State: It is information about the context in which the dialogue environment exists; besides state, reference materials and logs of the last few conversations may be provided, but state is there to remember the state of the dialogue otherwise. These include "things to remember," "themes of the dialogue," and "summary of the conversation.".'
|
|
94
|
+
],
|
|
95
|
+
state: [
|
|
96
|
+
(context) => {
|
|
97
|
+
if (!context.state?.content)
|
|
98
|
+
return null;
|
|
99
|
+
return {
|
|
100
|
+
type: 'text',
|
|
101
|
+
content: context.state.content
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=dialogue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialogue.js","sourceRoot":"","sources":["../../src/modules/dialogue.ts"],"names":[],"mappings":"AAwBA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAkC;IACzD,SAAS,EAAE;QACT,2EAA2E;KAC5E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ACL,uDAAuD;QACvD,uVAAuV;KACxV;IAED,YAAY,EAAE;QACZ,mLAAmL;QACnL,mDAAmD;KACpD;IAED,eAAe,EAAE;QACf,CAAC,OAAO,EAAE,EAAE;YACV,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO;gBAAE,OAAO,IAAI,CAAC;YACnD,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,OAAO;aACzC,CAAC;QACJ,CAAC;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkC;IAC1D,KAAK,EAAE;QACL,+VAA+V;KAChW;IAED,KAAK,EAAE;QACL,CAAC,OAAO,EAAE,EAAE;YACV,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;gBAAE,OAAO,IAAI,CAAC;YACzC,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;aAC/B,CAAC;QACJ,CAAC;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { withMaterials, answerWithReferences } from './material.js';
|
|
2
|
+
export type { MaterialContext } from './material.js';
|
|
3
|
+
export { streamProcessing } from './stream-processing.js';
|
|
4
|
+
export type { StreamProcessingContext } from './stream-processing.js';
|
|
5
|
+
export { dialogueBase, firstOfTwoPassResponse, secondOfTwoPassResponse, withTalkState } from './dialogue.js';
|
|
6
|
+
export type { DialogueContext } from './dialogue.js';
|
|
7
|
+
export { summarizeBase, analyzeForSummary, contentSummarize } from './summarize.js';
|
|
8
|
+
export type { SummarizeContext } from './summarize.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { withMaterials, answerWithReferences } from './material.js';
|
|
2
|
+
export { streamProcessing } from './stream-processing.js';
|
|
3
|
+
export { dialogueBase, firstOfTwoPassResponse, secondOfTwoPassResponse, withTalkState } from './dialogue.js';
|
|
4
|
+
export { summarizeBase, analyzeForSummary, contentSummarize } from './summarize.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACd,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PromptModule } from '@modular-prompt/core';
|
|
2
|
+
/**
|
|
3
|
+
* Material context interface
|
|
4
|
+
*/
|
|
5
|
+
export interface MaterialContext {
|
|
6
|
+
materials?: Array<{
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
content: string;
|
|
10
|
+
usage?: number;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Material module - handles external materials/documents
|
|
15
|
+
*/
|
|
16
|
+
export declare const withMaterials: PromptModule<MaterialContext>;
|
|
17
|
+
/**
|
|
18
|
+
* Material module with reference citation requirements
|
|
19
|
+
*/
|
|
20
|
+
export declare const answerWithReferences: PromptModule<MaterialContext>;
|
|
21
|
+
//# sourceMappingURL=material.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"material.d.ts","sourceRoot":"","sources":["../../src/modules/material.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,KAAK,CAAC;QAChB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;CACJ;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,eAAe,CAuBvD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,YAAY,CAAC,eAAe,CAW9D,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { merge } from '@modular-prompt/core';
|
|
2
|
+
/**
|
|
3
|
+
* Material module - handles external materials/documents
|
|
4
|
+
*/
|
|
5
|
+
export const withMaterials = {
|
|
6
|
+
terms: [
|
|
7
|
+
'Materials: the content of a web page or other text that has been imported into the system.',
|
|
8
|
+
'Material ID: An ID representing a material used for manipulating the material, described as "[<title>](<material ID>)".',
|
|
9
|
+
'The Learned Knowledge: Knowledge that you, the Assistant, have already learned.',
|
|
10
|
+
'Prepared Contextual Materials: Materials retrieved from the DB and explicitly provided. Materials that are not prepared cannot be accessed.'
|
|
11
|
+
],
|
|
12
|
+
materials: [
|
|
13
|
+
(context) => {
|
|
14
|
+
if (!context.materials || context.materials.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
return context.materials.map(material => {
|
|
17
|
+
const { id, title, content, usage } = material;
|
|
18
|
+
return {
|
|
19
|
+
type: 'material',
|
|
20
|
+
id,
|
|
21
|
+
title,
|
|
22
|
+
content,
|
|
23
|
+
usage
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Material module with reference citation requirements
|
|
31
|
+
*/
|
|
32
|
+
export const answerWithReferences = merge(withMaterials, {
|
|
33
|
+
instructions: [
|
|
34
|
+
'Ensure that responses to questions clearly distinguish between information derived from prepared materials and learned knowledge.',
|
|
35
|
+
'Always include the ID of the material when referencing information from prepared materials, using the format "(refs:<Material ID>)".',
|
|
36
|
+
'Even in the absence of prepared materials or specific references, or when the response is based on learned knowledge, always indicate the source of the information as "(refs:learned-knowledge)".',
|
|
37
|
+
'If information from multiple sources is used, each source should be cited accordingly.',
|
|
38
|
+
'If materials present different perspectives or conflicting information, report the facts that can be inferred from the materials. Avoid forcing a summary.'
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=material.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"material.js","sourceRoot":"","sources":["../../src/modules/material.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAe7C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkC;IAC1D,KAAK,EAAE;QACL,4FAA4F;QAC5F,yHAAyH;QACzH,iFAAiF;QACjF,6IAA6I;KAC9I;IACD,SAAS,EAAE;QACT,CAAC,OAAO,EAAE,EAAE;YACV,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAC;YAEtE,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBACtC,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC;gBAC/C,OAAO;oBACL,IAAI,EAAE,UAAmB;oBACzB,EAAE;oBACF,KAAK;oBACL,OAAO;oBACP,KAAK;iBACN,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAkC,KAAK,CACtE,aAAa,EACb;IACE,YAAY,EAAE;QACZ,mIAAmI;QACnI,sIAAsI;QACtI,oMAAoM;QACpM,wFAAwF;QACxF,4JAA4J;KAC7J;CACF,CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PromptModule } from '@modular-prompt/core';
|
|
2
|
+
/**
|
|
3
|
+
* Stream processing context interface
|
|
4
|
+
*/
|
|
5
|
+
export interface StreamProcessingContext {
|
|
6
|
+
chunks?: Array<{
|
|
7
|
+
content: string;
|
|
8
|
+
partOf?: string;
|
|
9
|
+
usage?: number;
|
|
10
|
+
attachments?: any[];
|
|
11
|
+
}>;
|
|
12
|
+
state?: {
|
|
13
|
+
content: string;
|
|
14
|
+
usage?: number;
|
|
15
|
+
};
|
|
16
|
+
range?: {
|
|
17
|
+
start?: number;
|
|
18
|
+
end?: number;
|
|
19
|
+
};
|
|
20
|
+
targetTokens?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Stream processing module - for processing large texts in chunks
|
|
24
|
+
*/
|
|
25
|
+
export declare const streamProcessing: PromptModule<StreamProcessingContext>;
|
|
26
|
+
//# sourceMappingURL=stream-processing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-processing.d.ts","sourceRoot":"","sources":["../../src/modules/stream-processing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;KACrB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,uBAAuB,CAmIlE,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream processing module - for processing large texts in chunks
|
|
3
|
+
*/
|
|
4
|
+
export const streamProcessing = {
|
|
5
|
+
objective: [
|
|
6
|
+
'The assistant functions as a non-interactive system that processes each iteration of stream processing.',
|
|
7
|
+
'The goal of the overall stream processing is to process the entire Source Text by dividing it into manageable chunks.',
|
|
8
|
+
'In this iteration, perform the specified processing on the Input Chunks and Current State, producing the Next State as output.',
|
|
9
|
+
(context) => {
|
|
10
|
+
// Detect if this is the first or last iteration based on range
|
|
11
|
+
if (!context.chunks || !context.range)
|
|
12
|
+
return null;
|
|
13
|
+
const isFirst = context.range.start === 0 || context.range.start === undefined;
|
|
14
|
+
const isLast = context.range.end === context.chunks.length;
|
|
15
|
+
if (isFirst && isLast) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'text',
|
|
18
|
+
content: 'This is a single-iteration processing. Complete all processing in this iteration.'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
else if (isFirst) {
|
|
22
|
+
return {
|
|
23
|
+
type: 'text',
|
|
24
|
+
content: 'This is the first iteration. Initialize the state with foundational information.'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else if (isLast) {
|
|
28
|
+
return {
|
|
29
|
+
type: 'text',
|
|
30
|
+
content: 'This is the final iteration. Ensure the Next State represents the complete processing result.'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
terms: [
|
|
37
|
+
'Stream Processing: A process of obtaining the final output by dividing the input data (the Source Text in this system) and performing iterative sequential processing.',
|
|
38
|
+
'Source Text: The text to be processed. It is divided into chunks, and several chunks are provided in each iteration.',
|
|
39
|
+
'Iteration: A unit of processing in stream processing. It is repeated to process time-series data or large segmented processing targets.',
|
|
40
|
+
'Chunk: A part of the source text divided based on chapter structure or text volume.',
|
|
41
|
+
'State: The text data updated in each iteration. The processing result of each iteration is retained.',
|
|
42
|
+
'Current State: The state at the beginning of an iteration, containing results from previous iterations.',
|
|
43
|
+
'Next State: The state produced by the current iteration, which becomes the Current State for the next iteration.'
|
|
44
|
+
],
|
|
45
|
+
methodology: [
|
|
46
|
+
'Read the Current State, which contains the processing results from previous iterations.',
|
|
47
|
+
'Process the provided Input Chunks according to the specified processing logic.',
|
|
48
|
+
'Merge the processing results with the Current State to create the Next State.',
|
|
49
|
+
'Ensure the Next State integrates all information processed so far.',
|
|
50
|
+
'Output only the Next State content without any formatting or metadata.',
|
|
51
|
+
(context) => {
|
|
52
|
+
// Add size control instructions if targetTokens is specified
|
|
53
|
+
if (!context.targetTokens)
|
|
54
|
+
return null;
|
|
55
|
+
const sizePrompt = `Control the Next State size to target ${context.targetTokens} tokens.`;
|
|
56
|
+
if (context.state?.usage && context.state.usage > context.targetTokens * 0.8) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'text',
|
|
59
|
+
content: `${sizePrompt} Current size is ${context.state.usage} tokens - aggressively reduce size while preserving key information.`
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
type: 'text',
|
|
64
|
+
content: `${sizePrompt} Aim for this target without exceeding it.`
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: 'subsection',
|
|
69
|
+
title: 'State Management',
|
|
70
|
+
items: [
|
|
71
|
+
'The Current State represents cumulative results from all previous iterations.',
|
|
72
|
+
'Each iteration processes only a portion of the entire Source Text.',
|
|
73
|
+
'The Next State must preserve important information from the Current State.',
|
|
74
|
+
'Merge new information with existing state rather than replacing it.',
|
|
75
|
+
'The final state after all iterations should represent the complete processing result.'
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
instructions: [
|
|
80
|
+
'The Source Text is divided into chunks and processed iteratively.',
|
|
81
|
+
'In each iteration, you receive the Current State (previous results) and new Input Chunks.',
|
|
82
|
+
'Your task is to process the chunks and update the state accordingly.',
|
|
83
|
+
'The output should be the Next State that will serve as input for the next iteration.'
|
|
84
|
+
],
|
|
85
|
+
state: [
|
|
86
|
+
(context) => {
|
|
87
|
+
if (!context.state?.content)
|
|
88
|
+
return null;
|
|
89
|
+
return {
|
|
90
|
+
type: 'chunk',
|
|
91
|
+
content: context.state.content,
|
|
92
|
+
partOf: 'state',
|
|
93
|
+
usage: context.state.usage
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
materials: [
|
|
98
|
+
(context) => {
|
|
99
|
+
if (!context.chunks || context.chunks.length === 0)
|
|
100
|
+
return null;
|
|
101
|
+
const chunks = context.chunks.slice(context.range?.start, context.range?.end);
|
|
102
|
+
if (chunks.length === 0)
|
|
103
|
+
return null;
|
|
104
|
+
return chunks.map((chunk, index) => ({
|
|
105
|
+
type: 'chunk',
|
|
106
|
+
content: chunk.content,
|
|
107
|
+
partOf: chunk.partOf || 'input',
|
|
108
|
+
index,
|
|
109
|
+
usage: chunk.usage
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
cue: [
|
|
114
|
+
'Below is the output for the Next State:'
|
|
115
|
+
],
|
|
116
|
+
guidelines: [
|
|
117
|
+
(context) => {
|
|
118
|
+
if (!context.targetTokens)
|
|
119
|
+
return null;
|
|
120
|
+
return {
|
|
121
|
+
type: 'text',
|
|
122
|
+
content: 'If the Target Size limit is likely to be exceeded, boldly discard information without fear of missing information. Simplify the presentation, remove duplicate content, remove non-obvious items.'
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
'Source text chunks provided in previous iterations are not accessible in the current iteration, so information extraction and importance review can only be done for a given chunk.'
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=stream-processing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-processing.js","sourceRoot":"","sources":["../../src/modules/stream-processing.ts"],"names":[],"mappings":"AAuBA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA0C;IACrE,SAAS,EAAE;QACT,yGAAyG;QACzG,uHAAuH;QACvH,gIAAgI;QAChI,CAAC,OAAO,EAAE,EAAE;YACV,+DAA+D;YAC/D,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK;gBAAE,OAAO,IAAI,CAAC;YAEnD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;YAC/E,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;YAE3D,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;gBACtB,OAAO;oBACL,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE,mFAAmF;iBAC7F,CAAC;YACJ,CAAC;iBAAM,I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