From 4d2a5c9c952b3bd940ce26ab3cdd2d9db0a954bd Mon Sep 17 00:00:00 2001 From: pelikhan Date: Mon, 19 Aug 2024 14:20:15 -0700 Subject: [PATCH 1/3] fix parmeters test case --- packages/core/src/parameters.ts | 9 +++++---- packages/sample/genaisrc/parameters.genai.js | 7 +++---- packages/sample/genaisrc/summarize-max-tokens.genai.js | 5 +++-- .../sample/genaisrc/summary-of-summary-phi3.genai.js | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/core/src/parameters.ts b/packages/core/src/parameters.ts index 5d607786ad..11c60c96af 100644 --- a/packages/core/src/parameters.ts +++ b/packages/core/src/parameters.ts @@ -25,16 +25,17 @@ export function promptParameterTypeToJSONSchema( } else if ( typeof t === "object" && - ["number", "integer", "string", "object"].includes((t as any).type) - ) + ["number", "integer", "string", "boolean", "object"].includes( + (t as any).type + ) + ) { return < | JSONSchemaNumber | JSONSchemaString | JSONSchemaBoolean | JSONSchemaObject >t - // TODO better filtering - else if (typeof t === "object") + } else if (typeof t === "object") return { type: "object", properties: Object.fromEntries( diff --git a/packages/sample/genaisrc/parameters.genai.js b/packages/sample/genaisrc/parameters.genai.js index 9bb067df36..f5efe20e52 100644 --- a/packages/sample/genaisrc/parameters.genai.js +++ b/packages/sample/genaisrc/parameters.genai.js @@ -35,6 +35,9 @@ script({ console.log(`string: ${env.vars.string} ${typeof env.vars.string}`) console.log(`number: ${env.vars.number} ${typeof env.vars.number}`) console.log(`boolean: ${env.vars.boolean} ${typeof env.vars.boolean}`) +console.log(`stringSchema: ${env.vars.stringSchema} ${typeof env.vars.stringSchema}`) +console.log(`numberSchema: ${env.vars.numberSchema} ${typeof env.vars.numberSchema}`) +console.log(`booleanSchema: ${env.vars.booleanSchema} ${typeof env.vars.booleanSchema}`) if (env.vars["string"] !== "abc") throw new Error("string parameter not set") if (env.vars["number"] !== 123) throw new Error("number parameter not set") @@ -45,7 +48,3 @@ if (env.vars["numberSchema"] !== 456) throw new Error("numberSchema parameter not set") if (env.vars["booleanSchema"] !== true) throw new Error("booleanSchema parameter not set") - -// use $ to output formatted text to the prompt -$`You are a helpful assistant. -` diff --git a/packages/sample/genaisrc/summarize-max-tokens.genai.js b/packages/sample/genaisrc/summarize-max-tokens.genai.js index 68ccda106c..cedfed205a 100644 --- a/packages/sample/genaisrc/summarize-max-tokens.genai.js +++ b/packages/sample/genaisrc/summarize-max-tokens.genai.js @@ -1,12 +1,13 @@ script({ title: "summarize with max tokens", model: "openai:gpt-3.5-turbo", + files: ["src/rag/*"], tests: { files: ["src/rag/*"], keywords: ["markdown", "lorem", "microsoft"], }, }) -def("FILE", env.files, { maxTokens: 20 }) +def("FILE", env.files, { maxTokens: 40 }) -$`Summarize each file. Be concise.` +$`Extract keywords for the contents of FILE.` diff --git a/packages/sample/genaisrc/summary-of-summary-phi3.genai.js b/packages/sample/genaisrc/summary-of-summary-phi3.genai.js index c7a231226f..f91ddd107c 100644 --- a/packages/sample/genaisrc/summary-of-summary-phi3.genai.js +++ b/packages/sample/genaisrc/summary-of-summary-phi3.genai.js @@ -1,7 +1,7 @@ script({ model: "ollama:phi3", title: "summary of summary - phi3", - files: ["src/rag/*.md"], + files: ["src/rag/*.md"], tests: { files: ["src/rag/*.md"], keywords: ["markdown", "lorem", "microsoft"], @@ -13,11 +13,11 @@ for (const file of env.files) { const { text } = await runPrompt( (_) => { _.def("FILE", file) - _.$`Summarize the FILE and respond in plain text with one paragraph. Be consice. Ensure that summary is consistent with the content of FILE.` + _.$`Extract keywords for the contents of FILE.` }, { model: "ollama:phi3", cacheName: "summary_phi3" } ) def("FILE", { ...file, content: text }) } // use summary -$`Summarize FILE with short sentence.` +$`Extract keywords for the contents of FILE.` From 7247180bb74a2a85c6f64cd2cf7dab5a3810aa2d Mon Sep 17 00:00:00 2001 From: pelikhan Date: Mon, 19 Aug 2024 14:30:39 -0700 Subject: [PATCH 2/3] add pr-create --- packages/sample/genaisrc/pr-create.genai.mts | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 packages/sample/genaisrc/pr-create.genai.mts diff --git a/packages/sample/genaisrc/pr-create.genai.mts b/packages/sample/genaisrc/pr-create.genai.mts new file mode 100644 index 0000000000..6f000d82de --- /dev/null +++ b/packages/sample/genaisrc/pr-create.genai.mts @@ -0,0 +1,60 @@ +script({ + model: "openai:gpt-4-32k", + files: [], + temperature: 1, + title: "pr-describe", + system: ["system", "system.fs_find_files", "system.fs_read_file"], +}) + +const defaultBranch = (env.vars.defaultBranch || "main") + "" +const { text, finishReason, error } = await runPrompt(async (_) => { + const { stdout: changes } = await host.exec("git", [ + "diff", + defaultBranch, + "--", + ".", + ":!**/genaiscript.d.ts", + ":!**/*sconfig.json", + ":!genaisrc/*", + ":!.github/*", + ":!.vscode/*", + ":!*yarn.lock", + ":!*THIRD_PARTY_LICENSES.md", + ]) + + _.def("GIT_DIFF", changes, { + language: "diff", + maxTokens: 20000, + }) + + _.$`You are an expert software developer and architect. + +## Task + +Create a pull request title and description for the changes in GIT_DIFF. + +The first line of the response should be the title of the pull request, the rest should be the description. + + + <description...> + +## Title Instructions + +- the title should be less than 50 characters + +## Description Instructions + +- do NOT explain that GIT_DIFF displays changes in the codebase +- try to extract the intent of the changes, don't focus on the details +- use bullet points to list the changes +- use emojis to make the description more engaging +- focus on the most important changes +- ignore comments about imports (like added, remove, changed, etc.) +- the public API is defined in "packages/core/src/prompt_template.d.ts" and "packages/core/src/prompt_type.ts". + Changes in those files are "user facing". +` +}) + +// exec output +console.log(error) +console.log(text) \ No newline at end of file From 3e3dbad6c100ea886ffac796cad63c83ea3dd6ec Mon Sep 17 00:00:00 2001 From: pelikhan <jhalleux@microsoft.com> Date: Mon, 19 Aug 2024 14:31:56 -0700 Subject: [PATCH 3/3] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9e4bd9ee7..6cebce4a4f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # GenAIScript -Scripting environment with convenient tooling for file ingestion, prompt development and structured data extraction. +JavaScript-ish environment with convenient tooling for file ingestion, prompt development and structured data extraction. ```js wrap // metadata and model configuration