retort-js
Version:
Intuitive, production-ready prompt chaining in Javascript
98 lines (97 loc) • 2.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RetortConversation = void 0;
const agent_1 = require("./agent");
const id_1 = require("./id");
const extendable_function_1 = require("./extendable-function");
const define_input_1 = require("./define-input");
const define_generation_1 = require("./define-generation");
const define_prompt_1 = require("./define-prompt");
const run_1 = require("./run");
class RetortConversation extends extendable_function_1.RetortExtendableFunction {
constructor() {
super(...arguments);
this.id = (0, id_1.id)("cnv");
/**
* @deprecated
*/
this.chat = this;
this.settings = {
model: "gpt-3.5-turbo",
temperature: 1,
topP: 1,
};
this.run = run_1.run;
this.messages = [];
this.user = (0, agent_1.agent)(this, "user");
this.assistant = (0, agent_1.agent)(this, "assistant");
this.system = (0, agent_1.agent)(this, "system");
}
get __wrappedFunction() {
return this.prompt;
}
get model() {
return this.settings.model;
}
set model(value) {
this.settings.model = value.toString();
}
get temperature() {
return this.settings.temperature;
}
set temperature(value) {
this.settings.temperature = value;
}
get topP() {
return this.settings.topP;
}
set topP(value) {
this.settings.topP = value;
}
/**
* Use the promise property of each message to get an array of promises
* @deprecated
*/
get messagePromises() {
return this.messages.map((m) => m.promise);
}
get input() {
return (0, define_input_1.defineInput)(this, "user", false);
}
;
get generation() {
return (0, define_generation_1.defineGeneration)(this, "assistant", false);
}
get prompt() {
return (0, define_prompt_1.definePrompt)(this, "user", false);
}
/**
* Use the toJSON method
* @deprecated
*/
toObject(messages = this.messages) {
return {
id: this.id,
settings: this.settings,
messages,
};
}
toJSON() {
return {
id: this.id,
settings: this.settings,
messages: this.messages,
};
}
/**
* If you need this create a fromJSON method
* @deprecated
*/
static fromObject(obj) {
const conversation = new RetortConversation();
conversation.settings = obj.settings;
conversation.messages.push(...obj.messages);
return conversation;
}
}
exports.RetortConversation = RetortConversation;