-
Notifications
You must be signed in to change notification settings - Fork 134
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
++Enable caching for LLM requests with configurable cache names #677
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,21 @@ | |
--- | ||
|
||
import { FileTree } from "@astrojs/starlight/components" | ||
|
||
Check warning on line 10 in docs/src/content/docs/reference/scripts/cache.mdx GitHub Actions / build
|
||
LLM requests are cached by default. This means that if a script generates the same prompt for the same model, the cache may be used. | ||
LLM requests are **NOT** cached by default. However, you can turn on LLM request caching from `script` metadata or the CLI arguments. | ||
|
||
- the `temperature` is less than 0.5 | ||
- the `top_p` is less than 0.5 | ||
- no [functions](./functions.md) are used as they introduce randomness | ||
- `seed` is not used | ||
```js "cache: true" | ||
script({ | ||
..., | ||
cache: true | ||
}) | ||
``` | ||
|
||
or | ||
|
||
```sh "--cache" | ||
npx genaiscript run ... --cache | ||
``` | ||
Check notice on line 24 in docs/src/content/docs/reference/scripts/cache.mdx GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New content has been added to explain how to enable LLM request caching. This includes a JavaScript code snippet and a shell command. Ensure that these instructions are correct and clear for users.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New code examples have been added to illustrate how to enable LLM request caching. Ensure these examples are correct and clear to the reader.
|
||
|
||
The cache is stored in the `.genaiscript/cache/chat.jsonl` file. You can delete this file to clear the cache. | ||
This file is excluded from git by default. | ||
|
@@ -26,32 +34,15 @@ | |
|
||
</FileTree> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The section on disabling the cache has been removed. If this information is still relevant and useful, consider adding it back to the documentation.
|
||
## Disabling | ||
|
||
You can always disable the cache using the `cache` option in `script`. | ||
|
||
```js | ||
script({ | ||
..., | ||
cache: false // always off | ||
}) | ||
``` | ||
|
||
Or using the `--no-cache` flag in the CLI. | ||
|
||
```sh | ||
npx genaiscript run .... --no-cache | ||
``` | ||
|
||
## Custom cache file | ||
|
||
Use the `cacheName` option to specify a custom cache file name. | ||
The name will be used to create a file in the `.genaiscript/cache` directory. | ||
|
||
```js | ||
script({ | ||
..., | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The property name in the JavaScript code snippet has been changed from 'cacheName' to 'cache'. This could potentially confuse users if not properly explained in the surrounding text.
|
||
cacheName: "summary" | ||
cache: "summary" | ||
Check warning on line 45 in docs/src/content/docs/reference/scripts/cache.mdx GitHub Actions / build
|
||
}) | ||
Check failure on line 46 in docs/src/content/docs/reference/scripts/cache.mdx GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The section on disabling the cache has been removed. If this information is still relevant, it should be included in the documentation.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The section on disabling the cache has been removed. This information might be important for users who want to disable caching. Consider adding it back or providing an alternative way to disable caching.
|
||
``` | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,13 +101,15 @@ | |
exitCode === SUCCESS_ERROR_CODE || | ||
UNRECOVERABLE_ERROR_CODES.includes(exitCode) | ||
) | ||
break | ||
|
||
const delayMs = 2000 * Math.pow(2, r) | ||
console.error( | ||
`error: run failed with ${exitCode}, retry #${r + 1}/${runRetry} in ${delayMs}ms` | ||
) | ||
await delay(delayMs) | ||
if (runRetry > 1) { | ||
console.error( | ||
`error: run failed with ${exitCode}, retry #${r + 1}/${runRetry} in ${delayMs}ms` | ||
) | ||
await delay(delayMs) | ||
} | ||
Check failure on line 112 in packages/cli/src/run.ts GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The retry logic has been changed to only retry if
|
||
} | ||
process.exit(exitCode) | ||
} | ||
|
@@ -156,7 +158,7 @@ | |
const jsSource = options.jsSource | ||
|
||
const fail = (msg: string, exitCode: number) => { | ||
logVerbose(msg) | ||
logError(msg) | ||
return { exitCode, result } | ||
} | ||
|
||
|
@@ -303,9 +305,6 @@ | |
return fail("runtime error", RUNTIME_ERROR_CODE) | ||
} | ||
if (!isQuiet) logVerbose("") // force new line | ||
if (result.status !== "success" && result.status !== "cancelled") | ||
logVerbose(result.statusText ?? result.status) | ||
|
||
if (outAnnotations && result.annotations?.length) { | ||
if (isJSONLFilename(outAnnotations)) | ||
await appendJSONL(outAnnotations, result.annotations) | ||
|
@@ -485,8 +484,10 @@ | |
} | ||
} | ||
// final fail | ||
if (result.error && !isCancelError(result.error)) | ||
return fail(errorMessage(result.error), RUNTIME_ERROR_CODE) | ||
if (result.status !== "success" && result.status !== "cancelled") { | ||
const msg = errorMessage(result.error) ?? result.statusText | ||
return fail(msg, RUNTIME_ERROR_CODE) | ||
} | ||
|
||
if (failOnErrors && result.annotations?.some((a) => a.severity === "error")) | ||
return fail("error annotations found", ANNOTATION_ERROR_CODE) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,10 +67,10 @@ | |
maxTokens: string | ||
maxToolCalls: string | ||
maxDataRepairs: string | ||
model: string | ||
Check failure on line 70 in packages/core/src/server/messages.ts GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type of
|
||
embeddingsModel: string | ||
csvSeparator: string | ||
cache: boolean | ||
cache: boolean | string | ||
cacheName: string | ||
applyEdits: boolean | ||
failOnErrors: boolean | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statement about LLM requests caching has been changed. It was previously stated that LLM requests are cached by default, but the updated content states that they are not cached by default. This is a significant change and should be verified for accuracy.