Skip to content

Commit

Permalink
Update token limits and refactor unique name handling in prompt resol…
Browse files Browse the repository at this point in the history
…ution
  • Loading branch information
pelikhan committed Sep 20, 2024
1 parent ad9927b commit cd20d4b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,5 @@ export const OPENAI_MAX_RETRY_DELAY = 10000
export const OPENAI_MAX_RETRY_COUNT = 10
export const OPENAI_RETRY_DEFAULT_DEFAULT = 1000

export const TEMPLATE_ARG_FILE_MAX_TOKENS = 1000
export const TEMPLATE_ARG_DATA_SLICE_SAMPLE = 1000
export const TEMPLATE_ARG_FILE_MAX_TOKENS = 4000
export const TEMPLATE_ARG_DATA_SLICE_SAMPLE = 2000
31 changes: 16 additions & 15 deletions packages/core/src/promptdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ async function resolvePromptNode(
const encoder = await resolveTokenEncoder(model)
let err = 0
const names = new Set<string>()
const uniqueName = (name: string) => {
const uniqueName = (n_: string) => {
let i = 1
let n = name
let n = n_
while (names.has(n)) {
n = `${name}${i++}`
n = `${n_}${i++}`
}
names.add(n)
return n
Expand Down Expand Up @@ -526,28 +526,29 @@ async function resolvePromptNode(
)
) {
// env.files
const name = uniqueName("FILES")
const fname = uniqueName("FILES")
n.children = n.children ?? []
for (const r of ra) {
n.children.push(
createDef(name, r, {
createDef(fname, r, {
ignoreEmpty: true,
maxTokens:
TEMPLATE_ARG_FILE_MAX_TOKENS,
})
)
}
ra = name
ra = fname
} else {
const dname = uniqueName("DATA")
n.children = [
...(n.children ?? []),
createDefData(dname, ra, {
sliceSample:
TEMPLATE_ARG_DATA_SLICE_SAMPLE,
}),
]
ra = dname
}
} else {
const name = uniqueName("DATA")
n.children = [
...(n.children ?? []),
createDefData(name, ra, {
sliceSample: TEMPLATE_ARG_DATA_SLICE_SAMPLE,
}),
]
ra = name
}
resolvedArgs.push(ra ?? "")
} catch (e) {
Expand Down
10 changes: 8 additions & 2 deletions packages/sample/genaisrc/nested-args.genai.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
script({
title: "summarize with nested arguments",
model: "openai:gpt-3.5-turbo",
files: "src/rag/markdown.md",
files: ["src/rag/markdown.md", "src/penguins.csv"],
tests: [
{
files: "src/rag/markdown.md",
Expand All @@ -10,4 +10,10 @@ script({
],
})

$`Summarize ${env.files}.`
const data = [
{ a: 1, b: 2 },
{ a: 3, b: 4 },
]

$`Summarize ${env.files[0]} and ${env.files.slice(1)} ${"in"} ${3} ${async () => "sentence"}.
${data}`

0 comments on commit cd20d4b

Please sign in to comment.