mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix: add freshness to Perplexity cache key + use unique test query to avoid cache collision
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -83,3 +83,4 @@ USER.md
|
||||
.agent/*.json
|
||||
!.agent/workflows/
|
||||
local/
|
||||
package-lock.json
|
||||
|
||||
@@ -569,7 +569,7 @@ async function runWebSearch(params: {
|
||||
params.provider === "brave"
|
||||
? `${params.provider}:${params.query}:${params.count}:${params.country || "default"}:${params.search_lang || "default"}:${params.ui_lang || "default"}:${params.freshness || "default"}`
|
||||
: params.provider === "perplexity"
|
||||
? `${params.provider}:${params.query}:${params.perplexityBaseUrl ?? DEFAULT_PERPLEXITY_BASE_URL}:${params.perplexityModel ?? DEFAULT_PERPLEXITY_MODEL}`
|
||||
? `${params.provider}:${params.query}:${params.perplexityBaseUrl ?? DEFAULT_PERPLEXITY_BASE_URL}:${params.perplexityModel ?? DEFAULT_PERPLEXITY_MODEL}:${params.freshness || "default"}`
|
||||
: `${params.provider}:${params.query}:${params.grokModel ?? DEFAULT_GROK_MODEL}:${String(params.grokInlineCitations ?? false)}`,
|
||||
);
|
||||
const cached = readCache(SEARCH_CACHE, cacheKey);
|
||||
|
||||
@@ -159,7 +159,7 @@ describe("web_search perplexity baseUrl defaults", () => {
|
||||
expect(body.model).toBe("sonar-pro");
|
||||
});
|
||||
|
||||
it("rejects freshness for Perplexity provider", async () => {
|
||||
it("passes freshness to Perplexity provider as search_recency_filter", async () => {
|
||||
vi.stubEnv("PERPLEXITY_API_KEY", "pplx-test");
|
||||
const mockFetch = vi.fn(() =>
|
||||
Promise.resolve({
|
||||
@@ -174,10 +174,11 @@ describe("web_search perplexity baseUrl defaults", () => {
|
||||
config: { tools: { web: { search: { provider: "perplexity" } } } },
|
||||
sandboxed: true,
|
||||
});
|
||||
const result = await tool?.execute?.(1, { query: "test", freshness: "pw" });
|
||||
await tool?.execute?.(1, { query: "perplexity-freshness-test", freshness: "pw" });
|
||||
|
||||
expect(mockFetch).not.toHaveBeenCalled();
|
||||
expect(result?.details).toMatchObject({ error: "unsupported_freshness" });
|
||||
expect(mockFetch).toHaveBeenCalledOnce();
|
||||
const body = JSON.parse(mockFetch.mock.calls[0][1].body as string);
|
||||
expect(body.search_recency_filter).toBe("week");
|
||||
});
|
||||
|
||||
it("defaults to OpenRouter when OPENROUTER_API_KEY is set", async () => {
|
||||
|
||||
Reference in New Issue
Block a user