Skip to content

Commit

Permalink
Improve script compilation wording, enhance function definitions, and…
Browse files Browse the repository at this point in the history
… optimize agent response computation
  • Loading branch information
pelikhan committed Sep 24, 2024
1 parent 1eca1f7 commit 184ca4e
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 52 deletions.
4 changes: 2 additions & 2 deletions docs/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -133,7 +133,7 @@ Commands:
list List all available scripts in workspace
create <name> Create a new script
fix fix all definition files
compile [folders...] Compile all script in workspace
compile [folders...] Compile all scripts in workspace
model [options] [script] List model connection information for scripts
help [command] display help for command
```
Expand Down Expand Up @@ -179,7 +179,7 @@ Options:
```
Usage: genaiscript scripts compile [options] [folders...]
Compile all script in workspace
Compile all scripts in workspace
Arguments:
folders Pattern to match files
Expand Down
4 changes: 2 additions & 2 deletions genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/auto/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/src/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions packages/core/src/runpromptcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function createChatTurnGenerationContext(
},
assistant: (body, options) =>
ctx.writeText(body, { ...options, assistant: true }),
$(strings, ...args) {
$: (strings, ...args) => {
const current = createStringTemplateNode(strings, args)
appendChild(node, current)
const res: PromptTemplateString = Object.freeze(<
Expand Down Expand Up @@ -88,7 +88,7 @@ export function createChatTurnGenerationContext(
})
return res
},
def(name, body, defOptions) {
def: (name, body, defOptions) => {
name = name ?? ""
const doptions = { ...(defOptions || {}), trace }
doptions.lineNumbers = doptions.lineNumbers ?? options.lineNumbers
Expand Down Expand Up @@ -141,10 +141,25 @@ export function createChatTurnGenerationContext(
node,
createDef(
name,
{ filename: "", content: (body as Fenced).content },
{ filename: "", content: fenced.content },
{ language: fenced.language, ...(doptions || {}) }
)
)
} else if (
typeof body === "object" &&
(body as RunPromptResult).text
) {
const res = body as RunPromptResult
const fence =
res.fences?.length === 1 ? res.fences[0] : undefined
appendChild(
node,
createDef(
name,
{ filename: "", content: fence?.content ?? res.text },
{ language: fence?.language, ...(doptions || {}) }
)
)
}

// TODO: support clause
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/prompt_template.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ interface ChatTurnGenerationContext {
fence(body: StringLike, options?: FenceOptions): void
def(
name: string,
body: string | WorkspaceFile | WorkspaceFile[] | ShellOutput | Fenced,
body: string | WorkspaceFile | WorkspaceFile[] | ShellOutput | Fenced | RunPromptResult,
options?: DefOptions
): string
defData(
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/prompt_type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ declare function fence(body: StringLike, options?: FenceOptions): void
*/
declare function def(
name: string,
body: string | WorkspaceFile | WorkspaceFile[] | ShellOutput | Fenced,
body: string | WorkspaceFile | WorkspaceFile[] | ShellOutput | Fenced | RunPromptResult,
options?: DefOptions
): string

Expand Down
4 changes: 2 additions & 2 deletions packages/sample/genaisrc/blog/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions packages/sample/genaisrc/mixture-of-agents.genai.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export async function mixtureOfAgents(
],
} = options ?? {}

// compute agent responses
const agentResponses = []
for (const agent of agents) {
const res = await runPrompt(
(ctx) => {
ctx.writeText(query)
ctx.assistant(`What do you think?`)
},
{ ...agent, label: agent.label || agent.model }
// compute agent responses concurrently
const agentResponses = await Promise.all(
agents.map((agent) =>
runPrompt(
(ctx) => {
ctx.writeText(query)
ctx.assistant(`What do you think?`)
},
{ ...agent, label: agent.label || agent.model }
)
)
agentResponses.push(res.text)
}
)

// critique
const { text: critique } = await runPrompt(
Expand Down
4 changes: 2 additions & 2 deletions packages/sample/genaisrc/node/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/genaisrc/python/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/genaisrc/style/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/src/aici/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/src/errors/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/src/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/src/makecode/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/src/tla/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/sample/src/vision/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/vscode/genaisrc/genaiscript.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 184ca4e

Please sign in to comment.