|
|
import { BasePromptTemplate } from './base-prompt-template.js';
|
|
|
import { SystemMessage } from '../core/message.js';
|
|
|
import { PromptTemplate } from './prompt-template.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class SystemMessagePromptTemplate extends BasePromptTemplate {
|
|
|
constructor(options = {}) {
|
|
|
super(options);
|
|
|
this.prompt = options.prompt || new PromptTemplate({
|
|
|
template: options.template,
|
|
|
inputVariables: options.inputVariables,
|
|
|
partialVariables: options.partialVariables
|
|
|
});
|
|
|
|
|
|
|
|
|
if (!options.inputVariables) {
|
|
|
this.inputVariables = this.prompt.inputVariables;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async format(values) {
|
|
|
this._validateInput(values);
|
|
|
const allValues = this._mergePartialAndUserVariables(values);
|
|
|
|
|
|
const content = await this.prompt.format(allValues);
|
|
|
return new SystemMessage(content);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static fromTemplate(template, options = {}) {
|
|
|
return new SystemMessagePromptTemplate({
|
|
|
template,
|
|
|
...options
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static fromTemplateWithPartials(template, partialVariables = {}, options = {}) {
|
|
|
const promptTemplate = new PromptTemplate({ template });
|
|
|
const inputVariables = promptTemplate.inputVariables.filter(
|
|
|
v => !(v in partialVariables)
|
|
|
);
|
|
|
|
|
|
return new SystemMessagePromptTemplate({
|
|
|
template,
|
|
|
inputVariables,
|
|
|
partialVariables,
|
|
|
...options
|
|
|
});
|
|
|
}
|
|
|
} |