mirror of
https://github.com/voideditor/void
synced 2026-05-24 01:48:25 +00:00
triple tick
This commit is contained in:
parent
e2e8279fce
commit
96b5b72d30
1 changed files with 28 additions and 24 deletions
|
|
@ -10,6 +10,10 @@ import { CodeSelection, StagingSelectionItem, FileSelection } from '../chatThrea
|
|||
import { VSReadFile } from '../helpers/readFile.js';
|
||||
import { IModelService } from '../../../../../editor/common/services/model.js';
|
||||
|
||||
|
||||
// this is just for ease of readability
|
||||
const tripleTick = ['```', '```']
|
||||
|
||||
export const chat_systemMessage = `\
|
||||
You are a coding assistant. You are given a list of instructions to follow \`INSTRUCTIONS\`, and optionally a list of relevant files \`FILES\`, and selections inside of files \`SELECTIONS\`.
|
||||
|
||||
|
|
@ -29,7 +33,7 @@ Do not tell the user anything about the examples below.
|
|||
## EXAMPLE 1
|
||||
FILES
|
||||
math.ts
|
||||
\`\`\`typescript
|
||||
${tripleTick[0]}typescript
|
||||
const addNumbers = (a, b) => a + b
|
||||
const multiplyNumbers = (a, b) => a * b
|
||||
const subtractNumbers = (a, b) => a - b
|
||||
|
|
@ -58,21 +62,21 @@ const normalized = (vector: number[]) => {
|
|||
const v2 = [...vector] // clone vector
|
||||
return normalize(v2)
|
||||
}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
|
||||
SELECTIONS
|
||||
math.ts (lines 3:3)
|
||||
\`\`\`typescript
|
||||
${tripleTick[0]}typescript
|
||||
const subtractNumbers = (a, b) => a - b
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
INSTRUCTIONS
|
||||
add a function that exponentiates a number below this, and use it to make a power function that raises all entries of a vector to a power
|
||||
|
||||
ACCEPTED OUTPUT
|
||||
We can add the following code to the file:
|
||||
\`\`\`typescript
|
||||
${tripleTick[0]}typescript
|
||||
// existing code...
|
||||
const subtractNumbers = (a, b) => a - b
|
||||
const exponentiateNumbers = (a, b) => Math.pow(a, b)
|
||||
|
|
@ -84,13 +88,13 @@ const raiseAll = (vector: number[], power: number) => {
|
|||
vector[i] = exponentiateNumbers(vector[i], power)
|
||||
return vector
|
||||
}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
|
||||
## EXAMPLE 2
|
||||
FILES
|
||||
fib.ts
|
||||
\`\`\`typescript
|
||||
${tripleTick[0]}typescript
|
||||
|
||||
const dfs = (root) => {
|
||||
if (!root) return;
|
||||
|
|
@ -102,20 +106,20 @@ const fib = (n) => {
|
|||
if (n < 1) return 1
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
SELECTIONS
|
||||
fib.ts (lines 10:10)
|
||||
\`\`\`typescript
|
||||
${tripleTick[0]}typescript
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
INSTRUCTIONS
|
||||
memoize results
|
||||
|
||||
ACCEPTED OUTPUT
|
||||
To implement memoization in your Fibonacci function, you can use a JavaScript object to store previously computed results. This will help avoid redundant calculations and improve performance. Here's how you can modify your function:
|
||||
\`\`\`typescript
|
||||
${tripleTick[0]}typescript
|
||||
// existing code...
|
||||
const fib = (n, memo = {}) => {
|
||||
if (n < 1) return 1;
|
||||
|
|
@ -123,7 +127,7 @@ const fib = (n, memo = {}) => {
|
|||
memo[n] = fib(n - 1, memo) + fib(n - 2, memo); // Store result in memo
|
||||
return memo[n];
|
||||
}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
Explanation:
|
||||
Memoization Object: A memo object is used to store the results of Fibonacci calculations for each n.
|
||||
Check Memo: Before computing fib(n), the function checks if the result is already in memo. If it is, it returns the stored result.
|
||||
|
|
@ -137,17 +141,17 @@ type FileSelnLocal = { fileURI: URI, content: string }
|
|||
const stringifyFileSelection = ({ fileURI, content }: FileSelnLocal) => {
|
||||
return `\
|
||||
${fileURI.fsPath}
|
||||
\`\`\`${filenameToVscodeLanguage(fileURI.fsPath) ?? ''}
|
||||
${tripleTick[0]}${filenameToVscodeLanguage(fileURI.fsPath) ?? ''}
|
||||
${content}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
`
|
||||
}
|
||||
const stringifyCodeSelection = ({ fileURI, selectionStr, range }: CodeSelection) => {
|
||||
return `\
|
||||
${fileURI.fsPath} (lines ${range.startLineNumber}:${range.endLineNumber})
|
||||
\`\`\`${filenameToVscodeLanguage(fileURI.fsPath) ?? ''}
|
||||
${tripleTick[0]}${filenameToVscodeLanguage(fileURI.fsPath) ?? ''}
|
||||
${selectionStr}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
`
|
||||
}
|
||||
|
||||
|
|
@ -201,14 +205,14 @@ export const fastApply_userMessage = ({ originalCode, applyStr, uri }: { origina
|
|||
|
||||
return `\
|
||||
ORIGINAL_FILE
|
||||
\`\`\`${language}
|
||||
${tripleTick[0]}${language}
|
||||
${originalCode}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
CHANGE
|
||||
\`\`\`
|
||||
${tripleTick[0]}
|
||||
${applyStr}
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
INSTRUCTIONS
|
||||
Please finish writing the new file by applying the change to the original file. Return ONLY the completion of the file, without any explanation.
|
||||
|
|
@ -309,9 +313,9 @@ export const ctrlKStream_userMessage = ({ selection, prefix, suffix, instruction
|
|||
return `\
|
||||
|
||||
CURRENT SELECTION
|
||||
\`\`\`${language}
|
||||
${tripleTick[0]}${language}
|
||||
<${midTag}>${selection}</${midTag}>
|
||||
\`\`\`
|
||||
${tripleTick[1]}
|
||||
|
||||
INSTRUCTIONS
|
||||
${instructions}
|
||||
|
|
@ -319,8 +323,8 @@ ${instructions}
|
|||
<${preTag}>${prefix}</${preTag}>
|
||||
<${sufTag}>${suffix}</${sufTag}>
|
||||
|
||||
Return only the completion block of code (of the form \`\`\`${language}
|
||||
Return only the completion block of code (of the form ${tripleTick[0]}${language}
|
||||
<${midTag}>...new code</${midTag}>
|
||||
\`\`\`).`
|
||||
${tripleTick[1]}).`
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue