Improve refinement (#69)

* Format construction function on return

* Add more refinement examples

* Treat 503 like 429

* Define prompt as object

* Fix prettier
This commit is contained in:
arcticfly
2023-07-20 13:05:27 -07:00
committed by GitHub
parent 55c077d604
commit 86dc36a656
4 changed files with 184 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ export async function constructPrompt(
): Promise<JSONSerializable> {
const code = `
const scenario = ${JSON.stringify(scenario ?? {}, null, 2)};
let prompt
let prompt = {};
${variant.constructFn}

View File

@@ -6,6 +6,7 @@ import { openai } from "./openai";
import { getApiShapeForModel } from "./getTypesForModel";
import { isObject } from "lodash-es";
import { type CompletionCreateParams } from "openai/resources/chat/completions";
import formatPromptConstructor from "~/utils/formatPromptConstructor";
const isolate = new ivm.Isolate({ memoryLimit: 128 });
@@ -65,9 +66,8 @@ const requestUpdatedPromptFunction = async (
});
}
messages.push({
role: "user",
content:
"The prompt variable has already been declared, so do not declare it again. Rewrite the entire prompt constructor function.",
role: "system",
content: "The prompt variable has already been declared, so do not declare it again.",
});
const completion = await openai.chat.completions.create({
model: "gpt-4",
@@ -111,7 +111,7 @@ const requestUpdatedPromptFunction = async (
const args = await contructPromptFunctionArgs.copy(); // Get the actual value from the isolate
if (args && isObject(args) && "new_prompt_function" in args) {
newContructionFn = args.new_prompt_function as string;
newContructionFn = await formatPromptConstructor(args.new_prompt_function as string);
break;
}
} catch (e) {