Skip to content

Commit

Permalink
Update VSCode extension with genaiscript annotations (#712)
Browse files Browse the repository at this point in the history
* Add genaiscript annotations and problem matcher to VSCode extension

* Update constants, add VSCode tasks, enhance problem matchers, and modify task provider

* Add task provider options for msCompile, lessCompile, and jshint

* Update vision model identifier from gpt-4-turbo-v to gpt-4o in business card scanner guide

* Normalize severity case and update nullish coalescing in annotations and promptrunner.
  • Loading branch information
pelikhan authored Sep 16, 2024
1 parent 42067d3 commit b9f59f4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/src/content/docs/guides/business-card-scanner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ This guide shows how to use vision and image variables to scan business card inf

## Vision model

You will need access to a deployment of the OpenAI vision model. In this example, it is identifier by `gpt-4-turbo-v`.
You will need access to a deployment of the OpenAI vision model. In this example, it is identifier by `gpt-4o`.
Also set the `maxTokens` to 4000 to ensure the model can process the entire business card.

```js "gpt-4-turbo-v"
```js "gpt-4o"
script({
...
model: "openai:gpt-4-turbo-v",
model: "openai:gpt-4o",
maxTokens: 4000,
})
```
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function parseAnnotations(text: string): Diagnostic[] {
const addAnnotation = (m: RegExpMatchArray) => {
const { file, line, endLine, severity, code, message } = m.groups
const annotation: Diagnostic = {
severity: sevMap[severity] ?? "info",
severity: sevMap[severity?.toLowerCase()] ?? "info",
filename: file,
range: [
[parseInt(line) - 1, 0],
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ export const CLIENT_RECONNECT_DELAY = 3000
export const CLIENT_RECONNECT_MAX_ATTEMPTS = 20
export const RETRIEVAL_PERSIST_DIR = "retrieval"
export const HIGHLIGHT_LENGTH = 4000
export const DEFAULT_MODEL = "openai:gpt-4-turbo"
export const DEFAULT_MODEL = "openai:gpt-4o"
export const DEFAULT_MODEL_CANDIDATES = [
"azure:gpt-4o",
"azure:gpt-4-turbo",
DEFAULT_MODEL,
"github:gpt-4o",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/promptrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ export async function runTemplate(
annotations.map((a) => ({
...a,
line: a.range?.[0]?.[0],
endLine: a.range?.[1]?.[0] || "",
code: a.code || "",
endLine: a.range?.[1]?.[0] ?? "",
code: a.code ?? "",
})),
{
headers: [
Expand Down
12 changes: 12 additions & 0 deletions packages/sample/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "echo \"::error file=src/fib.ts,line=1,endLine=5,code=concatenation_override::hello\""
}
]
}
5 changes: 5 additions & 0 deletions packages/sample/genaisrc/annotations.genai.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
script({ model: "gpt-4o", system: ["annotations"] })
def("FILE", env.files, { ignoreEmpty: true })

$`Review FILE and report errors and warnings using annotation format.
Answer in plain text.`
20 changes: 20 additions & 0 deletions packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@
},
"contributes": {
"markdown.markdownItPlugins": true,
"problemMatchers": [
{
"name": "genaiscript",
"label": "GenAIScript annotations",
"source": "Generated by a LLM.",
"applyTo": "allDocuments",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^\\s*::(info|notice|warning|error)\\s+file=([^,]+),\\s*line=(\\d+)(,\\s*endLine=(\\d+)\\s*)?(,\\s*code=([^,:]+)?\\s*)?::(.*)$",
"severity": 1,
"file": 2,
"line": 3,
"code": 7,
"message": 8
}
}
],
"taskDefinitions": [
{
"type": "genaiscript",
Expand Down
15 changes: 11 additions & 4 deletions packages/vscode/src/taskprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function activeTaskProvider(state: ExtensionState) {
: `npx --yes genaiscript@${cliVersion}`
const scripts = state.project.templates.filter((t) => !t.isSystem)
const tasks = scripts.map((script) => {
const scriptp = host.path.relative(
const scriptName = host.path.relative(
host.projectFolder(),
script.filename
)
Expand All @@ -27,12 +27,19 @@ export async function activeTaskProvider(state: ExtensionState) {
TOOL_ID,
new vscode.ShellExecution(exec, [
"run",
scriptp,
scriptName,
"${relativeFile}",
])
)
task.detail = `${script.title ?? script.description} - ${scriptp}`
task.problemMatchers = ["$tsc"]
task.detail = `${script.title ?? script.description} - ${scriptName}`
task.problemMatchers = [
"$genaiscript",
"$eslint-compact",
"$tsc",
"$msCompile",
"$lessCompile",
"$jshint",
]
task.presentationOptions = {
echo: true,
focus: true,
Expand Down

0 comments on commit b9f59f4

Please sign in to comment.