From e6e2c706c2d1f29e246b14cbe662ac526531da6e Mon Sep 17 00:00:00 2001 From: arcticfly <41524992+arcticfly@users.noreply.github.com> Date: Wed, 19 Jul 2023 17:19:45 -0700 Subject: [PATCH] Change up refinement UI (#66) * Remove unused ScenarioVariantCell fields * Refine deriveNewConstructFn * Fix prettier * Remove migration script * Add refine modal * Fix prettier * Fix diff checker overflow * Decrease diff height * Add more context to prompt refining * Auto-expand prompt when refining --- .../RefinePromptModal/CompareFunctions.tsx | 5 +- .../RefinePromptModal/RefinePromptModal.tsx | 70 +++++++++++++++---- src/server/utils/deriveNewContructFn.ts | 59 +++++++++++++++- 3 files changed, 116 insertions(+), 18 deletions(-) diff --git a/src/components/RefinePromptModal/CompareFunctions.tsx b/src/components/RefinePromptModal/CompareFunctions.tsx index abb2ed1..276481a 100644 --- a/src/components/RefinePromptModal/CompareFunctions.tsx +++ b/src/components/RefinePromptModal/CompareFunctions.tsx @@ -12,7 +12,6 @@ const CompareFunctions = ({ originalFunction: string; newFunction?: string; }) => { - console.log("newFunction", newFunction); const highlightSyntax = (str: string) => { let highlighted; try { @@ -25,17 +24,17 @@ const CompareFunctions = ({ }; return ( - + diff --git a/src/components/RefinePromptModal/RefinePromptModal.tsx b/src/components/RefinePromptModal/RefinePromptModal.tsx index 0983aaa..838fabc 100644 --- a/src/components/RefinePromptModal/RefinePromptModal.tsx +++ b/src/components/RefinePromptModal/RefinePromptModal.tsx @@ -11,12 +11,16 @@ import { Text, Spinner, HStack, + InputGroup, + Input, + InputRightElement, + Icon, } from "@chakra-ui/react"; +import { IoMdSend } from "react-icons/io"; import { api } from "~/utils/api"; import { useHandledAsyncCallback } from "~/utils/hooks"; import { type PromptVariant } from "@prisma/client"; import { useState } from "react"; -import AutoResizeTextArea from "../AutoResizeTextArea"; import CompareFunctions from "./CompareFunctions"; export const RefinePromptModal = ({ @@ -56,12 +60,20 @@ export const RefinePromptModal = ({ - Refine Your Prompt + Refine with GPT-4 - - - + + setInstructions(e.target.value)} onKeyDown={(e) => { @@ -71,12 +83,41 @@ export const RefinePromptModal = ({ getRefinedPromptFn(); } }} - placeholder="Use chain of thought" + placeholder="Send instructions" + py={7} + px={4} + colorScheme="orange" + borderColor="gray.300" + borderWidth={1} + _hover={{ + borderColor: "gray.300", + }} + _focus={{ + borderColor: "gray.300", + }} /> - - + + + + - - + diff --git a/src/server/utils/deriveNewContructFn.ts b/src/server/utils/deriveNewContructFn.ts index 65b3611..5614744 100644 --- a/src/server/utils/deriveNewContructFn.ts +++ b/src/server/utils/deriveNewContructFn.ts @@ -40,6 +40,59 @@ const requestUpdatedPromptFunction = async ( ) => { const originalModel = originalVariant.model as SupportedModel; let newContructionFn = ""; + const usefulTips = `Chain of thought means asking the model to think about its answer before it gives it to you. This is useful for getting more accurate answers. + + This is what a prompt looks like without using function calls: + + prompt = { + model: "gpt-4", + stream: true, + messages: [ + { + role: "system", + content: \`Evaluate sentiment.\`, + }, + { + role: "user", + content: \`This is the user's message: \${scenario.user_message}. Return "positive" or "negative" or "neutral"\`, + }, + ], + }; + + This is what one looks like using function calls: + + prompt = { + model: "gpt-3.5-turbo-0613", + stream: true, + messages: [ + { + role: "system", + content: "Evaluate sentiment.", + }, + { + role: "user", + content: scenario.user_message, + }, + ], + functions: [ + { + name: "extract_sentiment", + parameters: { + type: "object", + properties: { + sentiment: { + type: "string", + description: "one of positive/negative/neutral", + }, + }, + }, + }, + ], + function_call: { + name: "extract_sentiment", + }, + }; + `; for (let i = 0; i < NUM_RETRIES; i++) { try { const messages: CompletionCreateParams.CreateChatCompletionRequestNonStreaming.Message[] = [ @@ -49,7 +102,7 @@ const requestUpdatedPromptFunction = async ( getApiShapeForModel(originalModel), null, 2, - )}`, + )}\n\nDo not add any assistant messages.`, }, ]; if (newModel) { @@ -59,6 +112,10 @@ const requestUpdatedPromptFunction = async ( }); } if (instructions) { + messages.push({ + role: "system", + content: `Here is some useful information about prompt engineering: ${usefulTips}`, + }); messages.push({ role: "user", content: `Follow these instructions: ${instructions}`,