-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add string template node * string template node * removed error var * add aici rendering * add AICI to api * add cli tracing * note about escaping * better formatting * percolate aici * more plumbing * weave aici into openai call * capitalize * more plumbing * more wiring * wiring of chat messages * make key format more generic * retreive aici token * key mess * more plumbing * fix tokens * add version to token * parse aici keys * pickup secret per template * going further * move logging * tracing generated aici * better function names * don't trace aici * update call * convert more messages * support for system prompts using aici * log url * rename url to base in token * fixed codegen issue * encoding regexes * fixes for azure connection * more key parsing * fixed azure key * more docs * better codegen to avoid backgracking * expose AICI.gen({ storeVar: ... }) as fences * fix typo * example of substring constraint * add `genVars` to output * support for runPrompt * merge issues * updated d.ts --------- Co-authored-by: Michal Moskal <[email protected]>
- Loading branch information
Showing
46 changed files
with
2,493 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
title: AICI | ||
sidebar: | ||
order: 200 | ||
--- | ||
|
||
[Microsoft AICI](https://github.com/microsoft/aici/) allows to constrain the output of a LLM using WASM. In particular, it is possible to send JavaScript program to describe the prompt. | ||
|
||
GenAIScript support executing scripts and converting the output into a AICI compatible JavaScript program, which will them generate constrainted output. | ||
|
||
:::caution | ||
|
||
This feature is experimental and may change in the future. | ||
|
||
::: | ||
|
||
Let's take a look at an example. | ||
|
||
```js title="answer-to-everything.genai.js" | ||
$`Ultimate answer is to the life, universe | ||
and everything is ${AICI.gen({ regex: /\d\d/ })}` | ||
``` | ||
|
||
The execution of this script is converted into a AICI JavaScript program. | ||
|
||
```js title="answer-to-everything.aici.js" | ||
async function aiciregex() { | ||
await $`Ultimate answer is to the life, universe and everything is ` | ||
await gen({regex: /\d\d/}) | ||
} | ||
|
||
async function main() { | ||
await aiciregex() | ||
} | ||
start(main) | ||
``` | ||
|
||
And AICI comes back with the following log. | ||
|
||
```txt | ||
FIXED "Ultimate answer is to the life, universe and everything is " | ||
GEN-OPT {regex: /\d\d/} | ||
regex constraint: "\\d\\d" | ||
dfa: 160 bytes | ||
GEN "42" | ||
JsCtrl: done | ||
``` | ||
|
||
And the text output is `42`. | ||
|
||
|
||
## Metadata | ||
|
||
An AICI template should set the `aici: true` field in the `script` function. | ||
|
||
```js title="answer-to-everything.genai.js" | ||
script({ ... | ||
aici: true, | ||
}) | ||
``` | ||
|
||
## `gen` | ||
|
||
The `AICI.gen` function creates a constrain in the prompt flow. | ||
|
||
## Token | ||
|
||
AICI uses `AICI_API_KEY`, `AICI_API_BASE` and `AICI_API_VERSION` (default `v1`) to compose the API URL. | ||
|
||
``` | ||
<base>/<model>/<version>/run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.