Skip to content

Commit

Permalink
refactor: update file handling and improve scripts structure 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 6, 2024
1 parent bde92c1 commit 95c9575
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 73 deletions.
29 changes: 15 additions & 14 deletions packages/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,25 @@ export async function runScript(
if (GENAI_ANY_REGEX.test(scriptId)) toolFiles.push(scriptId)

for (const arg of files) {
if (HTTPS_REGEX.test(arg)) {
resolvedFiles.add(arg)
continue
}
const stats = await host.statFile(arg)
if (!stats)
return fail(`file not found: ${arg}`, FILES_NOT_FOUND_ERROR_CODE)
if (stats.type !== "file") continue
if (HTTPS_REGEX.test(arg)) resolvedFiles.add(arg)
else {
const ffs = await host.findFiles(arg, {
applyGitIgnore: excludeGitIgnore,
})
if (!ffs?.length) {
return fail(
`no files matching ${arg} under ${process.cwd()}`,
FILES_NOT_FOUND_ERROR_CODE
)
}
for (const file of ffs) {
resolvedFiles.add(filePathOrUrlToWorkspaceFile(file))
}
const ffs = await host.findFiles(arg, {
applyGitIgnore: excludeGitIgnore,
})
if (!ffs?.length) {
return fail(
`no files matching ${arg} under ${process.cwd()}`,
FILES_NOT_FOUND_ERROR_CODE
)
}
for (const file of ffs) {
resolvedFiles.add(filePathOrUrlToWorkspaceFile(file))
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/sample/genaisrc/llm-as-expert.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ script({
system: ["system", "system.assistant", "system.tools"],
tests: {
keywords: [
"Permanent Waves",
"Moving Pictures",
"Signals",
"Power Windows",
Expand Down
1 change: 1 addition & 0 deletions packages/sample/genaisrc/prediction.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
script({
model: "openai:gpt-4o",
group: "openai",
files: "src/greeter.ts",
tests: {
files: "src/greeter.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/sample/genaisrc/summarize-link.genai.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ script({
group: "hello world",
system: ["system", "system.files"],
temperature: 0,
files: "https://raw.githubusercontent.com/microsoft/genaiscript/main/packages/sample/src/rag/markdown.md",
tests: {
files: "https://raw.githubusercontent.com/microsoft/genaiscript/main/packages/sample/src/rag/markdown.md",
keywords: "markdown",
Expand Down
22 changes: 0 additions & 22 deletions packages/sample/genaisrc/summarize-ollama-gemma2.genai.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/sample/genaisrc/summary-of-summary-gpt35.genai.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
script({
model: "small",
title: "summary of summary - phi3",
files: ["src/rag/*.md"],
files: "src/rag/*",
tests: {
files: ["src/rag/*.md"],
files: ["src/rag/*"],
keywords: ["markdown", "lorem", "microsoft"],
},
})

if (!env.files.length) throw new Error("No files found")
// summarize each files individually
for (const file of env.files) {
const { text } = await runPrompt(
(_) => {
_.def("FILE", file)
_.$`Extract keywords for the contents of FILE.`
},
{ model: "ollama:phi3", cache: "summary_phi3" }
{ model: "small", cache: "summary_summary" }
)
def("FILE", { ...file, content: text })
}
Expand Down
18 changes: 10 additions & 8 deletions packages/sample/genaisrc/todo.genai.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ script({
description: "Try to implement TODOs found in source code.",
group: "samples",
system: ["system", "system.files"],
temperature: 0,
model: "small",
model: "large",
files: "src/fib.ts",
tests: {
files: "src/fib.ts",
asserts: [{
type: "javascript",
transform: "output",
value: "Object.keys(output.fileEdits).length > 0"
}]
}
asserts: [
{
type: "javascript",
transform: "output",
value: "Object.keys(output.fileEdits).length > 0",
},
],
},
})

def("CODE", env.files, { lineNumbers: true })
Expand Down

0 comments on commit 95c9575

Please sign in to comment.