Skip to content

Commit

Permalink
feat: add role support to prompt templates and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 22, 2024
1 parent e59aa53 commit dfbb3ba
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface PromptStringTemplateNode extends PromptNode {
args: any[] // Arguments for the template
transforms: ((s: string) => Awaitable<string>)[] // Transform functions to apply to the template
resolved?: string // Resolved templated content
role?: ChatMessageRole
}

// Interface for an import template node.
Expand Down Expand Up @@ -1097,7 +1098,12 @@ export async function renderPromptNode(
},
stringTemplate: async (n) => {
const value = n.resolved
if (value != undefined) appendUser(value)
const role = n.role || "user"
if (value != undefined) {
if (role === "system") appendSystem(value)
else if (role === "assistant") appendAssistant(value)
else appendUser(value)
}
},
image: async (n) => {
const value = n.resolved
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/runpromptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ export function createChatTurnGenerationContext(
current.maxTokens = tokens
return res
},
role: (r) => {
current.role = r
return res
}
})
return res
},
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,11 @@ interface PromptTemplateString {
* @param tokens
*/
maxTokens(tokens: number): PromptTemplateString

/**
* Updates the role of the message
*/
role(role: ChatMessageRole): PromptTemplateString
}

interface ChatTurnGenerationContext {
Expand Down
23 changes: 23 additions & 0 deletions packages/vscode/genaisrc/lint.genai.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
script({
title: "Universal Linter",
description: "Review files for correctness and style",
model: "large",
})

$`## Task
You are Linty, an linter for all known programming languages and natural languages.
You are universally versed in all possible best practices
and you love to find and report issues in text, code or any content.
Your task is to review the content in FILE and report warnings and errors.
## Rules
- for each file in FILE, use best practices based on the file extension to review the content. For example, for a ".py" file, you should use Python best practices
- for non-code files, like markdown or text, check for spelling and grammatical issues.
- be exhaustive and report all issues you can find
- use the annotation format to report issues
- if you are not sure about a particular issue, do NOT report it
`.role("system")

def("FILE", env.files, { lineNumbers: true })

0 comments on commit dfbb3ba

Please sign in to comment.