Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameter fix #629

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/core/src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@
items: promptParameterTypeToJSONSchema(t[0]),
}
else if (
typeof t === "object" &&
["number", "integer", "string", "object"].includes((t as any).type)
)
["number", "integer", "string", "boolean", "object"].includes(
(t as any).type
)

Check failure on line 30 in packages/core/src/parameters.ts

View workflow job for this annotation

GitHub Actions / build

The type check `(t as any).type` might not be safe. Consider using a type guard function to ensure `t` is of the expected type. 🛡️

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type check (t as any).type might not be safe. Consider using a type guard function to ensure t is of the expected type. 🛡️

generated by pr-review-commit type_check

) {
return <
| JSONSchemaNumber
| JSONSchemaString
| JSONSchemaBoolean
| JSONSchemaObject

Check failure on line 36 in packages/core/src/parameters.ts

View workflow job for this annotation

GitHub Actions / build

The types `JSONSchemaBoolean` and `JSONSchemaObject` are declared but not used in the function. Consider removing or using them to avoid confusion. 🧹

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types JSONSchemaBoolean and JSONSchemaObject are declared but not used in the function. Consider removing or using them to avoid confusion. 🧹

generated by pr-review-commit unused_code

>t
// TODO better filtering
else if (typeof t === "object")
} else if (typeof t === "object")
return <JSONSchemaObject>{
type: "object",
properties: Object.fromEntries(

Check failure on line 41 in packages/core/src/parameters.ts

View workflow job for this annotation

GitHub Actions / build

The object creation `<JSONSchemaObject>{ type: "object", properties: Object.fromEntries() }` is missing arguments for `Object.fromEntries()`. This could lead to unexpected behavior. 🧩

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object type is being set to "object" without any checks. This could lead to unexpected behavior if t is not an object. Consider adding a type check before setting the type. 🧐

generated by pr-review-commit object_type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properties of the object are being set using Object.fromEntries(). This could lead to unexpected behavior if the entries are not key-value pairs. Consider adding a check to ensure the entries are in the correct format. 🕵️‍♀️

generated by pr-review-commit object_properties

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object creation <JSONSchemaObject>{ type: "object", properties: Object.fromEntries() } is missing arguments for Object.fromEntries(). This could lead to unexpected behavior. 🧩

generated by pr-review-commit object_creation

Object.entries(t).map(([k, v]) => [
k,
promptParameterTypeToJSONSchema(v),
Expand Down
7 changes: 3 additions & 4 deletions packages/sample/genaisrc/parameters.genai.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
`
60 changes: 60 additions & 0 deletions packages/sample/genaisrc/pr-create.genai.mts
Original file line number Diff line number Diff line change
@@ -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.

<title>
<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)
5 changes: 3 additions & 2 deletions packages/sample/genaisrc/summarize-max-tokens.genai.js
Original file line number Diff line number Diff line change
@@ -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.`
6 changes: 3 additions & 3 deletions packages/sample/genaisrc/summary-of-summary-phi3.genai.js
Original file line number Diff line number Diff line change
@@ -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"],
Expand All @@ -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.`
Loading