-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
task_execution.ts
31 lines (29 loc) · 1.24 KB
/
task_execution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { LLMChain, LLMChainInput } from "../../chains/llm_chain.js";
import { PromptTemplate } from "../../prompts/prompt.js";
/** Chain to execute tasks. */
export class TaskExecutionChain extends LLMChain {
static lc_name() {
return "TaskExecutionChain";
}
/**
* A static factory method that creates an instance of TaskExecutionChain.
* It constructs a prompt template for task execution, which is then used
* to create a new instance of TaskExecutionChain. The prompt template
* instructs an AI to perform a task based on a given objective, taking
* into account previously completed tasks.
* @param fields An object of type LLMChainInput, excluding the "prompt" field.
* @returns An instance of LLMChain.
*/
static fromLLM(fields: Omit<LLMChainInput, "prompt">): LLMChain {
const executionTemplate =
`You are an AI who performs one task based on the following objective: ` +
`{objective}.` +
`Take into account these previously completed tasks: {context}.` +
` Your task: {task}. Response:`;
const prompt = new PromptTemplate({
template: executionTemplate,
inputVariables: ["objective", "context", "task"],
});
return new TaskExecutionChain({ prompt, ...fields });
}
}