Hello World
Here is a simple example of an llm executor.
Step 2 - Prepare Prompt
ts
export const PROMPT = `We are conducting a test, follow the instructions exactly.
Do not ask questions or make conversation.
The user will provide an input, you need to reply only with:
"Hello World, you said <and then insert here what they said>".
So for example, if they say "Hello", you should reply only with:
Hello World, you said Hello.`;
Step 3 - Create LLM Executor
Combine the prompt, LLM, and parser into a single function.
ts
export async function helloWorld(llm: BaseLlm, input: string) {
const prompt = createPrompt("chat", PROMPT)
prompt.addUserMessage(input)
const parser = createParser("string");
return createLlmExecutor({
name: "extract",
llm,
prompt,
parser,
}).execute({});
}
Step 4 - Use it!
ts
import { extractInformation } from "./somewhere"
// a chat history, loaded from somewhere
const chatHistory = [];
const response = await extractInformation({
// the input you get from somewhere
input: "I'm going to be in berlin",
chatHistory
}, schema);
/**
*
* console.log(response)
* {
* "city": "Berlin",
* "startDate": "unknown",
* "endDate": "unknown",
* }
**/
// the intent is focused on the most recent message
chatHistory.push({
role: "user",
content: "I'm going to be in berlin"
});
const response2 = await identifyIntent().execute({
input: "I get there the 14th and leave the 18th",
chatHistory
}, schema);
/**
*
* console.log(response)
* {
* "city": "Berlin",
* "startDate": "06/14/2023",
* "endDate": "06/18/2023",
* }
**/
Complete File
ts
import { createPrompt, createParser, createLlmExecutor } from "llm-exe"
import type { BaseLlm } from "llm-exe"
export const PROMPT = `We are conducting a test, follow the instructions exactly.
Do not ask questions or make conversation.
The user will provide an input, you need to reply only with:
"Hello World, you said <and then insert here what they said>".
So for example, if they say "Hello", you should reply only with:
Hello World, you said Hello.`;
export async function helloWorld(llm: BaseLlm, input: string) {
const prompt = createPrompt("chat", PROMPT)
prompt.addUserMessage(input)
const parser = createParser("string");
return createLlmExecutor({
name: "extract",
llm,
prompt,
parser,
}).execute({});
}