Skip to content
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

cache #636

Closed
wants to merge 1 commit into from
Closed

cache #636

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/genaisrc/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion genaisrc/genaiscript.d.ts

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

6 changes: 2 additions & 4 deletions packages/core/src/chatcache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
ChatCompletationRequestCacheValue
>

export function getChatCompletionCache(
name?: string
): ChatCompletationRequestCache {
export function getChatCompletionCache(): ChatCompletationRequestCache {

Check failure on line 23 in packages/core/src/chatcache.ts

View workflow job for this annotation

GitHub Actions / build

The function `getChatCompletionCache` has been modified to no longer accept an argument. This could potentially break any existing calls to this function that are passing an argument.

Check failure on line 23 in packages/core/src/chatcache.ts

View workflow job for this annotation

GitHub Actions / build

The function `getChatCompletionCache` has been modified to no longer accept any arguments. This could potentially break any existing calls to this function that are passing arguments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function getChatCompletionCache has been modified to no longer accept an argument. This could potentially break any existing calls to this function that are passing an argument.

generated by pr-review-commit missing_argument

return JSONLineCache.byName<
ChatCompletionRequestCacheKey,
ChatCompletationRequestCacheValue
>(name || CHAT_CACHE)
>(CHAT_CACHE)
}
2 changes: 1 addition & 1 deletion packages/core/src/genaisrc/genaiscript.d.ts

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

3 changes: 1 addition & 2 deletions packages/core/src/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
maxCachedTemperature = MAX_CACHED_TEMPERATURE,
maxCachedTopP = MAX_CACHED_TOP_P,
cache: useCache,
cacheName,
retry,
retryDelay,
maxDelay,
Expand All @@ -68,7 +67,7 @@
const { model } = parseModelIdentifier(req.model)
const encoder = await resolveTokenEncoder(model)

const cache = getChatCompletionCache(cacheName)
const cache = getChatCompletionCache()

Check failure on line 70 in packages/core/src/openai.ts

View workflow job for this annotation

GitHub Actions / build

The function `getChatCompletionCache` is called without an argument. This could potentially break the functionality if the function was expected to handle different cache names.

Check failure on line 70 in packages/core/src/openai.ts

View workflow job for this annotation

GitHub Actions / build

The function call `getChatCompletionCache()` has been modified to no longer pass any arguments. This change is consistent with the modification of the `getChatCompletionCache` function, but it could potentially affect the behavior of the `OpenAIChatCompletion` function.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function getChatCompletionCache is called without an argument. This could potentially break the functionality if the function was expected to handle different cache names.

generated by pr-review-commit missing_argument

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function call getChatCompletionCache() has been modified to no longer pass any arguments. This change is consistent with the modification of the getChatCompletionCache function, but it could potentially affect the behavior of the OpenAIChatCompletion function.

generated by pr-review-commit changed_function_call

const caching =
useCache === true || // always use cache
(useCache !== false && // never use cache
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/promptrunner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { executeChatSession, tracePromptResult } from "./chat"
import { Project, PromptScript } from "./ast"
import { stringToPos } from "./parser"
import { arrayify, assert, logVerbose, relativePath } from "./util"
import { arrayify, assert, logError, logVerbose, relativePath } from "./util"
import { runtimeHost } from "./host"
import { applyLLMDiff, applyLLMPatch, parseLLMDiffs } from "./diff"
import { MarkdownTrace } from "./trace"
Expand Down Expand Up @@ -327,6 +327,7 @@
if (oannotations) annotations = oannotations.slice(0)
}
} catch (e) {
logError(e)

Check failure on line 330 in packages/core/src/promptrunner.ts

View workflow job for this annotation

GitHub Actions / build

An error is logged but not handled. This could lead to unexpected behavior or crashes. Consider throwing the error after logging, or handle it appropriately.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error is logged but not handled. This could lead to unexpected behavior or crashes. Consider throwing the error after logging, or handle it appropriately.

generated by pr-review-commit error_handling

trace.error(`output processor failed`, e)
} finally {
trace.endDetails()
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 @@ -618,7 +618,7 @@

type MakeOptional<T, P extends keyof T> = Partial<Pick<T, P>> & Omit<T, P>

type PromptArgs = Omit<PromptScript, "text" | "id" | "jsSource" | "activation">
type PromptArgs = Omit<PromptScript, "text" | "id" | "jsSource" | "activation", "cacheName">

Check failure on line 621 in packages/core/src/types/prompt_template.d.ts

View workflow job for this annotation

GitHub Actions / build

The type `PromptArgs` has been modified to omit the `cacheName` property from `PromptScript`. This could potentially break any existing code that relies on `cacheName` being a property of `PromptArgs`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type PromptArgs has been modified to omit the cacheName property from PromptScript. This could potentially break any existing code that relies on cacheName being a property of PromptArgs.

generated by pr-review-commit changed_type


type PromptSystemArgs = Omit<
PromptArgs,
Expand Down
22 changes: 21 additions & 1 deletion packages/sample/genaisrc/cache.genai.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
script({
model: "openai:gpt-3.5-turbo",
tests: {},
cache: true,
cacheName: "gpt-cache",
tests: [{}, {}], // run twice to trigger caching
})

const cache = await workspace.cache<number, number>("test-cache")
Expand All @@ -15,3 +17,21 @@ const values = await cache.values()
if (!values.includes(value)) throw new Error(`unexpected values: ${values}`)

console.log(`cache test passed`)

$`Generate a random word.`

defOutputProcessor(async ({ text }) => {
console.error(`process output`)
const pcache = await workspace.cache<string, string>("poem-cache")
const cached = await pcache.get("poem-result")
if (cached) {
console.error(`cache hit ${cached} | ${text}`)
if (cached !== text) {
console.error(`cached value mismatch`)
throw new Error(`unexpected cached value: ${cached}`)
}
} else {
console.error(`storing poem in cache`)
await pcache.set("poem-result", text)
}
})
2 changes: 1 addition & 1 deletion packages/sample/genaisrc/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/genaisrc/node/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/genaisrc/python/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/genaisrc/style/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/src/aici/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/src/errors/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/src/makecode/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/src/tla/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion packages/sample/src/vision/genaiscript.d.ts

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

2 changes: 1 addition & 1 deletion slides/genaisrc/genaiscript.d.ts

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

Loading