wirejs-deploy-amplify-basic 0.1.147-llm → 0.1.149-llm
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/dist/services/llm.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class LLM extends BaseLLM {
|
|
|
4
4
|
constructor(scope: Resource | string, id: string, options: {
|
|
5
5
|
models: string[];
|
|
6
6
|
systemPrompt?: string;
|
|
7
|
+
targetContextSize?: number;
|
|
7
8
|
});
|
|
8
9
|
private createBedrockInstructionMessage;
|
|
9
10
|
private convertToBedrockFormat;
|
|
@@ -11,5 +12,5 @@ export declare class LLM extends BaseLLM {
|
|
|
11
12
|
private invokeBedrock;
|
|
12
13
|
private streamBedrock;
|
|
13
14
|
private invokeModel;
|
|
14
|
-
continueConversation({ history, onChunk, timeoutSeconds }: ContinueConversationOptions): Promise<LLMMessage>;
|
|
15
|
+
continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, models, }: ContinueConversationOptions): Promise<LLMMessage>;
|
|
15
16
|
}
|
package/dist/services/llm.js
CHANGED
|
@@ -39,13 +39,13 @@ export class LLM extends BaseLLM {
|
|
|
39
39
|
};
|
|
40
40
|
return modelMap[model] || model;
|
|
41
41
|
}
|
|
42
|
-
async invokeBedrock(modelId, messages, stream, abortSignal) {
|
|
42
|
+
async invokeBedrock(modelId, systemPrompt, messages, stream, abortSignal) {
|
|
43
43
|
if (stream) {
|
|
44
44
|
const command = new ConverseStreamCommand({
|
|
45
45
|
modelId,
|
|
46
46
|
messages: this.convertToBedrockFormat(messages),
|
|
47
|
-
system:
|
|
48
|
-
text:
|
|
47
|
+
system: systemPrompt ? [{
|
|
48
|
+
text: systemPrompt
|
|
49
49
|
}] : undefined
|
|
50
50
|
});
|
|
51
51
|
return await this.bedrockClient.send(command, { abortSignal });
|
|
@@ -54,8 +54,8 @@ export class LLM extends BaseLLM {
|
|
|
54
54
|
const command = new ConverseCommand({
|
|
55
55
|
modelId,
|
|
56
56
|
messages: this.convertToBedrockFormat(messages),
|
|
57
|
-
system:
|
|
58
|
-
text:
|
|
57
|
+
system: systemPrompt ? [{
|
|
58
|
+
text: systemPrompt
|
|
59
59
|
}] : undefined
|
|
60
60
|
});
|
|
61
61
|
return await this.bedrockClient.send(command, { abortSignal });
|
|
@@ -96,14 +96,14 @@ export class LLM extends BaseLLM {
|
|
|
96
96
|
content
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
-
async invokeModel(model, history, onChunk, abortSignal, maxRetries = 10) {
|
|
99
|
+
async invokeModel(model, systemPrompt, history, onChunk, abortSignal, maxRetries = 10) {
|
|
100
100
|
const stream = typeof onChunk === 'function';
|
|
101
101
|
for (let i = 0; i < maxRetries; i++) {
|
|
102
102
|
try {
|
|
103
103
|
const modelId = this.getModelId(model);
|
|
104
104
|
if (modelId !== model)
|
|
105
105
|
console.log(`Mapped ${model} to ${modelId}`);
|
|
106
|
-
const response = await this.invokeBedrock(modelId, history, stream, abortSignal);
|
|
106
|
+
const response = await this.invokeBedrock(modelId, systemPrompt, history, stream, abortSignal);
|
|
107
107
|
if (stream) {
|
|
108
108
|
return this.streamBedrock(response, onChunk, abortSignal);
|
|
109
109
|
}
|
|
@@ -131,7 +131,7 @@ export class LLM extends BaseLLM {
|
|
|
131
131
|
}
|
|
132
132
|
throw new Error("Exceeded max retries trying to invoke " + model);
|
|
133
133
|
}
|
|
134
|
-
async continueConversation({ history, onChunk, timeoutSeconds }) {
|
|
134
|
+
async continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, models, }) {
|
|
135
135
|
const controller = new AbortController();
|
|
136
136
|
let timeoutId;
|
|
137
137
|
if (timeoutSeconds) {
|
|
@@ -142,9 +142,9 @@ export class LLM extends BaseLLM {
|
|
|
142
142
|
try {
|
|
143
143
|
// models are expected to be given in priority order. first one that doesn't
|
|
144
144
|
// throw a fit wins.
|
|
145
|
-
for (const model of this.models) {
|
|
145
|
+
for (const model of models ?? this.models) {
|
|
146
146
|
try {
|
|
147
|
-
const result = await this.invokeModel(model, history, onChunk, controller.signal);
|
|
147
|
+
const result = await this.invokeModel(model, (systemPrompt ?? this.systemPrompt) ?? '', history, onChunk, controller.signal);
|
|
148
148
|
if (!result)
|
|
149
149
|
throw new Error("No response from model.");
|
|
150
150
|
if (timeoutId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wirejs-deploy-amplify-basic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.149-llm",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"jsdom": "^25.0.0",
|
|
44
44
|
"recursive-copy": "^2.0.14",
|
|
45
45
|
"rimraf": "^6.0.1",
|
|
46
|
-
"wirejs-dom": "^1.0.
|
|
47
|
-
"wirejs-resources": "^0.1.
|
|
46
|
+
"wirejs-dom": "^1.0.44",
|
|
47
|
+
"wirejs-resources": "^0.1.149-llm"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@aws-amplify/backend": "^1.14.0",
|