forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Upstash Redis lookup parse value bug (langchain-ai#2765)
* fix: bug in upstash redis lookup * nit * fix: /* eslint-disable no-process-env */ * chore: lint * fix: type get result as StoredGeneration * fix: proper types on non int test --------- Co-authored-by: jacoblee93 <[email protected]>
- Loading branch information
1 parent
89a9aaf
commit 23b3199
Showing
3 changed files
with
45 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint-disable no-process-env */ | ||
import { ChatOpenAI } from "../../chat_models/openai.js"; | ||
import { UpstashRedisCache } from "../upstash_redis.js"; | ||
|
||
/** | ||
* This test is a result of the `lookup` method trying to parse an | ||
* incorrectly typed value Before it was being typed as a string, | ||
* whereas in reality it was a JSON object. | ||
*/ | ||
test.skip("UpstashRedisCache does not parse non string cached values", async () => { | ||
if ( | ||
!process.env.UPSTASH_REDIS_REST_URL || | ||
!process.env.UPSTASH_REDIS_REST_TOKEN || | ||
!process.env.OPENAI_API_KEY | ||
) { | ||
throw new Error( | ||
"Missing Upstash Redis REST URL // REST TOKEN or OpenAI API key" | ||
); | ||
} | ||
const upstashRedisCache = new UpstashRedisCache({ | ||
config: { | ||
url: process.env.UPSTASH_REDIS_REST_URL, | ||
token: process.env.UPSTASH_REDIS_REST_TOKEN, | ||
}, | ||
}); | ||
|
||
const chat = new ChatOpenAI({ | ||
temperature: 0, | ||
cache: upstashRedisCache, | ||
maxTokens: 10, | ||
}); | ||
|
||
const prompt = "is the sky blue"; | ||
const result1 = await chat.predict(prompt); | ||
const result2 = await chat.predict(prompt); | ||
|
||
expect(result1).toEqual(result2); | ||
}); |
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