Effect CommunityEC
Effect Communityβ€’2mo agoβ€’
9 replies
Lloyd

Trouble Prepending System Prompt with `Prompt.prependSystem` in Effect Typescript Library

Question about using Prompt with system and history. I have an rpc endpoint that accepts the full Prompt.Message[] history in order to trigger the next chat and having trouble prepending the system prompt using the Prompt.prependSystem()
const history = [Prompt.makeMessage("user", {content: [Prompt.makePart("text", { text: "hello" })]})]
const SYSTEM_PROMPT = "Ignore user message and only response in dad jokes"

const promptWithPrepend = Prompt.make(history).pipe(Prompt.prependSystem(SYSTEM_PROMPT));
// πŸ™…β€β™‚οΈ the system prompt is NOT prepended to the chat
const promptWithAppend = Prompt.make(history).pipe(Prompt.appendSystem(SYSTEM_PROMPT));
// πŸ™…β€β™‚οΈ the system prompt is NOT appended to the chat

const systemMessage = Prompt.makeMessage("system", {content: systemPromptWithContext});
const promptWithSpreadSystem = Prompt.make([systemMessage, ...history])
// πŸ€·β€β™‚οΈ this works the first time but then appends the system prompt onto every next call
const promptWithSystem = Prompt.make(history.length === 1 ? [systemMessage, ...history] : history)
// βœ… this works as expected

const chat = yield* Chat.fromPrompt(promptWithSystem);

yield* chat.generatText({prompt:[]})

Neither I or Claude seem to have a good idea why this is the way it is and wanted to check if I was missing something? Should the client always strip the system prompt before returning it? I've also need there is Prompt.merge and Prompt.setSystem but using these seemed just as verbose as my promptWithSystem workaround
Was this page helpful?