Skip to content

Instantly share code, notes, and snippets.

@Yankzy
Last active June 25, 2023 17:36
Show Gist options
  • Save Yankzy/e2d5927f70685ef085d2187c13878b05 to your computer and use it in GitHub Desktop.
Save Yankzy/e2d5927f70685ef085d2187c13878b05 to your computer and use it in GitHub Desktop.
Control shatGPT with system role
interface ChatMessage {
role: string;
content: string;
}
export const chatOrchestrator = (
chatHistory: ChatMessage[],
setChatList: (chatList: ChatMessage[]) => void
): void => {
const steps = ['introduction', 'specific goals', 'timeframe', 'metrics', 'action plan'];
const msg = (step: string) => `
Your next step is: ${step}.
Do not skip it and do not overwhelm the user with 2 steps at a time.`;
internalChat([
...chatHistory,
{ role: "system", content: 'Which step number are you now?' }
]).then((res) => {
for (let i = 0; i < steps.length; i++) {
if (res.toLowerCase().includes(steps[i]) || res.includes((i+1).toString())) {
setChatList([...chatHistory, { role: "system", content: msg(steps[i+1]) }])
break;
}
}
}).catch((err) => {
Logger('chatOrchestrator', err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment