-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
48 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ script({ | |
}, | ||
}) | ||
$`Say something.` | ||
assistant("Hello, world!") | ||
$`hello`.role("assistant") | ||
assistant("world!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,10 @@ | ||
script({ | ||
choices: ["FAIL", "SUCCESS"], | ||
tests: { | ||
keywords: "SUCCESS", | ||
}, | ||
}) | ||
script({}) | ||
def("FILE", "hello world") | ||
def("FILE", "hello world") | ||
|
||
defOutputProcessor((output) => { | ||
const msg = output.messages.find(m => m.role === "user") | ||
const msg = output.messages.find((m) => m.role === "user") | ||
console.log({ msg }) | ||
const fileCount = (msg.content.match(/<FILE>/g) || []).length; | ||
const fileCount = (msg.content.match(/<FILE>/g) || []).length | ||
if (fileCount > 2) throw new Error("Too many files") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
script({ | ||
tests: {} | ||
}) | ||
console.log({ runDir: env.runDir }) | ||
$`Generate a 1 sentence poem and save it to a text file.` | ||
defFileOutput("poem.txt", "the generated poem") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
script({ | ||
model: "ollama:deepseek-r1:1.5b" | ||
model: "ollama:deepseek-r1:1.5b", | ||
}) | ||
|
||
$`Think about a new joke and recite it.` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
script({ | ||
files: [], | ||
tests: {}, | ||
}) | ||
|
||
import { pipeline, env as transformersEnv } from "@huggingface/transformers" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
script({ | ||
files: "src/rag/*" | ||
files: "src/rag/*", | ||
tests: {}, | ||
}) | ||
|
||
import { pipeline, cos_sim } from '@huggingface/transformers'; | ||
import { pipeline, cos_sim } from "@huggingface/transformers" | ||
|
||
const featureExtractor = await pipeline('feature-extraction'); | ||
const featureExtractor = await pipeline("feature-extraction") | ||
|
||
// Function to rank documents | ||
async function rank(query: string, files: WorkspaceFile[]) { | ||
const documents = files.map(({ content }) => content); | ||
const documents = files.map(({ content }) => content) | ||
const queryEmbedding = (await featureExtractor(query)).tolist()[0][0] | ||
const similarities = await Promise.all(documents.map(async (doc, i) => { | ||
const docEmbedding = (await featureExtractor(doc)).tolist()[0][0] | ||
const score = cos_sim(queryEmbedding, docEmbedding); | ||
return { file: files[i], score }; | ||
})); | ||
similarities.sort((a, b) => b.score - a.score); | ||
const similarities = await Promise.all( | ||
documents.map(async (doc, i) => { | ||
const docEmbedding = (await featureExtractor(doc)).tolist()[0][0] | ||
const score = cos_sim(queryEmbedding, docEmbedding) | ||
return { file: files[i], score } | ||
}) | ||
) | ||
similarities.sort((a, b) => b.score - a.score) | ||
return similarities | ||
} | ||
|
||
// Example usage | ||
const query = "What is markdown?"; | ||
const query = "What is markdown?" | ||
const rankedDocs = await rank(query, env.files) | ||
console.log(rankedDocs) | ||
console.log(rankedDocs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters