Skip to content

Commit

Permalink
feat: ✨ add system message handling to promptdom
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Oct 18, 2024
1 parent 9104f0d commit a731dfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { dedent } from "./indent"
import {
ChatCompletionAssistantMessageParam,
ChatCompletionMessageParam,
ChatCompletionSystemMessageParam,
} from "./chattypes"
import { resolveTokenEncoder } from "./encoders"
import { expandFiles } from "./fs"
Expand Down Expand Up @@ -1078,10 +1079,15 @@ ${fods.map((fo) => ` ${fo.pattern}: ${fo.description}`)}
toChatCompletionUserMessage(userPrompt, images),
]
if (assistantPrompt)
messages.push(<ChatCompletionAssistantMessageParam>{
messages.push({
role: "assistant",
content: assistantPrompt,
})
} as ChatCompletionAssistantMessageParam)
if (systemPrompt)
messages.unshift({
role: "system",
content: systemPrompt,
} as ChatCompletionSystemMessageParam)
const res = Object.freeze<PromptNodeRender>({
userPrompt,
assistantPrompt,
Expand Down
8 changes: 8 additions & 0 deletions packages/sample/genaisrc/import-prompty.genai.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ script({
},
})

const res = await runPrompt((ctx) => {
ctx.importTemplate("src/basic.prompty", {
question: "what is the capital of france?",
hint: "starts with p",
})
})
console.log(`inline: ${res.text}`)

importTemplate("src/basic.prompty", {
question: "what is the capital of france?",
hint: "starts with p",
Expand Down

0 comments on commit a731dfe

Please sign in to comment.