Skip to content

Commit

Permalink
don't allow overriding the cache name in script
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Aug 20, 2024
1 parent aeabd7a commit 5b9c94d
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 22 deletions.
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 @@ export type ChatCompletationRequestCache = JSONLineCache<
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.
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 @@ export const OpenAIChatCompletion: ChatCompletionHandler = async (
maxCachedTemperature = MAX_CACHED_TEMPERATURE,
maxCachedTopP = MAX_CACHED_TOP_P,
cache: useCache,
cacheName,
retry,
retryDelay,
maxDelay,
Expand All @@ -68,7 +67,7 @@ export const OpenAIChatCompletion: ChatCompletionHandler = async (
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.
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 @@ export async function runTemplate(
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.
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 @@ interface ExpansionVariables {

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`.

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.

0 comments on commit 5b9c94d

Please sign in to comment.