Skip to content

Commit

Permalink
πŸ”„ Update model to "small" in all script definitions πŸ’» (#784)
Browse files Browse the repository at this point in the history
* πŸ”„ Update model to "small" in all script definitions πŸ’»

* feat: add smallModel support to API and config πŸš€

* πŸ“ docs: add env vars to override model configuration πŸ‘
  • Loading branch information
pelikhan authored Oct 17, 2024
1 parent 9775c66 commit 2dcbab5
Show file tree
Hide file tree
Showing 55 changed files with 82 additions and 60 deletions.
8 changes: 7 additions & 1 deletion docs/src/content/docs/getting-started/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ script({ model: "small" })
script({ model: "large" })
```

The model can also be overriden from the [cli run command](/genaiscript/reference/cli/run#model).
The model can also be overriden from the [cli run command](/genaiscript/reference/cli/run#model)
or by adding the `GENAISCRIPT_DEFAULT_MODEL` and `GENAISCRIPT_DEFAULT_SMALL_MODEL` environment variables.

```txt title=".env"
GENAISCRIPT_DEFAULT_MODEL="azure_serverless:..."
GENAISCRIPT_DEFAULT_SMALL_MODEL="azure_serverless:..."
```

## `.env` file

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Arguments:
Options:
--models <models...> models to test where mode is the key
value pair list of m (model), t
(temperature), p (top-p)
value pair list of m (model), s (small
model), t (temperature), p (top-p)
-o, --out <folder> output folder
-rmo, --remove-out remove output folder if it exists
--cli <string> override path to the cli
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export async function cli() {
)
.option(
"--models <models...>",
"models to test where mode is the key value pair list of m (model), t (temperature), p (top-p)"
"models to test where mode is the key value pair list of m (model), s (small model), t (temperature), p (top-p)"
)
.option("-o, --out <folder>", "output folder")
.option("-rmo, --remove-out", "remove output folder if it exists")
Expand Down
12 changes: 11 additions & 1 deletion packages/cli/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,20 @@ import { delay } from "es-toolkit"
* @returns A ModelOptions object with model, temperature, and topP fields if applicable.
*/
function parseModelSpec(m: string): ModelOptions {
const values = parseKeyValuePairs(m)
const values = m
.split(/&/g)
.map((kv) => kv.split("=", 2))
.reduce(
(acc, [key, value]) => {
acc[key] = decodeURIComponent(value)
return acc
},
{} as Record<string, string>
)
if (Object.keys(values).length > 1)
return {
model: values["m"],
smallModel: values["s"],
temperature: normalizeFloat(values["t"]),
topP: normalizeFloat(values["p"]),
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/genaiscript-api-provider.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GenAIScriptApiProvider {
}

async callApi(prompt, context) {
const { model, temperature, top_p, cache, version, cli, quiet } =
const { model, smallModel, temperature, top_p, cache, version, cli, quiet } =
this.config
const { vars, logger } = context
try {
Expand Down Expand Up @@ -51,6 +51,7 @@ class GenAIScriptApiProvider {
args.push("--json")
if (quiet) args.push("--quiet")
if (model) args.push("--model", model)
if (smallModel) args.push("--small-model", smallModel)
if (temperature !== undefined)
args.push("--temperature", temperature)
if (top_p !== undefined) args.push("--top_p", top_p)
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,27 @@ export function generatePromptFooConfiguration(
prompts: [id],
// Map model options to providers
providers: models
.map(({ model, temperature, topP }) => ({
.map(({ model, smallModel, temperature, topP }) => ({
model: model ?? host.defaultModelOptions.model,
smallModel: smallModel ?? host.defaultModelOptions.smallModel,
temperature: !isNaN(temperature)
? temperature
: host.defaultModelOptions.temperature,
top_p: topP,
}))
.map(({ model, temperature, top_p }) => ({
.map(({ model, smallModel, temperature, top_p }) => ({
id: provider,
label: [
model,
smallModel,
`t=${temperature}`,
top_p !== undefined ? `p=${top_p}` : undefined,
]
.filter((v) => v !== undefined)
.join(":"),
config: {
model,
smallModel,
temperature,
top_p,
cli,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ interface ModelConnectionOptions {
* @default gpt-4
* @example gpt-4
*/
smallModel?: OptionsOrString<"openai:gpt-4o-mini" | "openai:gpt-3.5-turbo">
smallModel?: OptionsOrString<
"openai:gpt-4o-mini" | "openai:gpt-3.5-turbo" | "azure:gpt-4o-mini"
>
}

interface ModelOptions extends ModelConnectionOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/blog-generate-knowledge.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "blog using generated knowledge",
model: "openai:gpt-3.5-turbo",
model: "small",
description:
"Using Generated Knowledge technique. More at https://learnprompting.org/docs/intermediate/generated_knowledge",
tests: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/console-eval.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {},
})

Expand Down
6 changes: 3 additions & 3 deletions packages/sample/genaisrc/csv.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
script({
files: "src/penguins.csv",
tests: {},
model: "openai:gpt-3.5-turbo",
model: "small",
})

def("DATA", env.files, { sliceSample: 3 })
Expand All @@ -18,9 +18,9 @@ const srows = CSV.parse(
`A|1
B|2
C|3`,
{ delimiter: ",", headers: ["name", "value"] }
{ delimiter: "|", headers: ["name", "value"] }
)
console.log(srows)
console.log({ srows })
if (
JSON.stringify(srows) ===
JSON.stringify([
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/defdata.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "defData demo",
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {
},
system: ["system"]
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/defschema.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
tests: {},
model: "openai:gpt-3.5-turbo",
model: "small",
files: "src/cities.md"
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "Describe objects in each image",
model: "openai:gpt-3.5-turbo",
model: "small",
group: "vision",
maxTokens: 4000,
system: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/diagrams.genai.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {},
})
$`Generate a diagram of a merge.`
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/exec.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {
keywords: ["Python", "3."],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/fetch.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {
keywords: "genaiscript",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/fileoutput.genai.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "summarize all files",
model: "openai:gpt-3.5-turbo",
model: "small",
files: "src/rag/markdown.md",
tests: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/flex.genai.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
files: ["src/rag/markdown.md"],
system: [],
flexTokens: 20,
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/fs.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tools: ["fs"],
tests: {},
})
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/fuzz-search.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "fuzz search",
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {},
})
const kw = (env.vars.keyword || "defdata") + ""
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/gcc-container.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
})
const container = await host.container({
image: "gcc",
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/git-history.genai.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
title: "git-history", tests: {} })

const author = env.vars.author as string || "pelikhan"
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/github.genai.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {},
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/html.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
title: "HTML to Text",
tests: {},
})
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/import-template.genai.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {
keywords: ["paris", "abracadabra"],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/json_object.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
responseType: "json_object",
responseSchema: {
type: "object",
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/json_object_ex.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
responseType: "json_object",
responseSchema: { characters: [{ name: "neo", age: 30 }] },
tests: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/llm-as-expert.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defTool(
},
async ({ prompt }) => {
const res = await env.generator.runPrompt(prompt, {
model: "openai:gpt-3.5-turbo",
model: "small",
label: "llm-gpt35",
})
return res.text
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/math-agent-system.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "math-agent-system",
model: "openai:gpt-3.5-turbo",
model: "small",
description: "A port of https://ts.llamaindex.ai/examples/agent",
system: ["system.math"],
parameters: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/mjs.genai.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "top-level-mjs",
model: "openai:gpt-3.5-turbo",
model: "small",
files: ["src/rag/markdown.md"],
tests: {
files: ["src/rag/markdown.md"],
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/mts.genai.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "top-level-ts",
model: "openai:gpt-3.5-turbo",
model: "small",
files: ["src/rag/markdown.md"],
tests: {
files: ["src/rag/markdown.md"],
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/multi-turn.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
title: "Multi-turn conversation",
files: ["src/rag/markdown.md"],
system: ["system", "system.files"],
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/nested-args.genai.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "summarize with nested arguments",
model: "openai:gpt-3.5-turbo",
model: "small",
files: ["src/rag/markdown.md", "src/penguins.csv"],
tests: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/output.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
title: "custom output",
files: "src/rag/markdown.md", tests: { files: "src/rag/markdown.md" },
system: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/pdf-to-tweet.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
title: "generate a tweet from a pdf file",
tests: {
files: "src/rag/loremipsum.pdf",
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/rag.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "rag",
model: "openai:gpt-3.5-turbo",
model: "small",
files: "src/rag/*",
tests: {
files: "src/rag/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/responseschema.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {
},
responseSchema: {
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/run-prompt-summarize.genai.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script({
title: "run prompt summarize",
model: "openai:gpt-3.5-turbo",
model: "small",
tests: [
{
files: ["src/rag/markdown.md"],
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/script-files.genai.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
script({
model: "openai:gpt-3.5-turbo",
model: "small",
files: "src/rag/*.md",
tests: {},
})
Expand Down
4 changes: 2 additions & 2 deletions packages/sample/genaisrc/style/runprompt.genai.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const resPoem = await runPrompt(
_.$`write haiku poem`
},
{
model: "openai:gpt-3.5-turbo",
model: "small",
label: "generate poem",
system: ["system"],
}
Expand All @@ -27,7 +27,7 @@ const resJSON = await runPrompt(
_.$`generate 3 random numbers between 1 and 10 and respond in JSON`
},
{
model: "openai:gpt-3.5-turbo",
model: "small",
label: "generate json",
responseType: "json_object",
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/summarize-files-function.genai.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
script({
title: "summarize-files-function",
tools: ["fs"],
model: "openai:gpt-3.5-turbo",
model: "small",
tests: {
files: ["src/rag/*"],
keywords: ["markdown", "lorem", "word"],
Expand Down
Loading

0 comments on commit 2dcbab5

Please sign in to comment.