chore(vendor): import pi 1.3.0
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
1 parent
719370c8f7
commit
6081e3e325
1743 files changed
+205459
-131704
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { stream as streamOpenAIResponses } from "../src/api/openai-responses.ts";
|
||||
import type { Model } from "../src/types.ts";
|
||||
import { normalizeContext } from "../src/utils/transcript.ts";
|
||||
|
||||
const model: Model<"openai-responses"> = {
|
||||
id: "gpt-5-mini",
|
||||
name: "GPT-5 Mini",
|
||||
api: "openai-responses",
|
||||
provider: "openai",
|
||||
baseUrl: "https://api.openai.com/v1",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 400000,
|
||||
maxTokens: 128000,
|
||||
};
|
||||
|
||||
const context = normalizeContext({
|
||||
systemPrompt: "",
|
||||
messages: [{ role: "user", content: [{ type: "text", text: "hi" }], timestamp: 0 }],
|
||||
tools: [],
|
||||
});
|
||||
|
||||
async function capturePayload(
|
||||
apiKey: string,
|
||||
requestModel: Model<"openai-responses"> = model,
|
||||
): Promise<Record<string, unknown>> {
|
||||
let payload: Record<string, unknown> | undefined;
|
||||
await streamOpenAIResponses(requestModel, context, {
|
||||
apiKey,
|
||||
maxTokens: 1000,
|
||||
temperature: 0.5,
|
||||
cacheRetention: "long",
|
||||
onPayload: (params) => {
|
||||
payload = params as Record<string, unknown>;
|
||||
},
|
||||
fetch: async () => new Response(null, { status: 500 }),
|
||||
}).result();
|
||||
if (!payload) throw new Error("Request payload was not captured");
|
||||
return payload;
|
||||
}
|
||||
|
||||
describe("OpenAI Responses with Sign in with ChatGPT", () => {
|
||||
it("omits request fields that token sharing rejects", async () => {
|
||||
const payload = await capturePayload("chatgpt-access-token");
|
||||
|
||||
expect(payload).not.toHaveProperty("max_output_tokens");
|
||||
expect(payload).not.toHaveProperty("temperature");
|
||||
expect(payload.prompt_cache_retention).toBeUndefined();
|
||||
});
|
||||
|
||||
it("omits prompt_cache_options on models with explicit prompt cache mode", async () => {
|
||||
const explicitCacheModel = { ...model, compat: { supportsExplicitPromptCacheMode: true } };
|
||||
|
||||
const signInPayload = await capturePayload("chatgpt-access-token", explicitCacheModel);
|
||||
const apiKeyPayload = await capturePayload("sk-proj-test", explicitCacheModel);
|
||||
|
||||
expect(signInPayload.prompt_cache_options).toBeUndefined();
|
||||
expect(apiKeyPayload.prompt_cache_options).toEqual({ ttl: "30m" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ name: "OpenAI API keys", apiKey: "sk-proj-test", requestModel: model },
|
||||
{
|
||||
name: "other OpenAI-compatible endpoints",
|
||||
apiKey: "gateway-key",
|
||||
requestModel: { ...model, baseUrl: "https://gateway.example.com/v1" },
|
||||
},
|
||||
])("keeps those fields for $name", async ({ apiKey, requestModel }) => {
|
||||
const payload = await capturePayload(apiKey, requestModel);
|
||||
|
||||
expect(payload.max_output_tokens).toBe(1000);
|
||||
expect(payload.temperature).toBe(0.5);
|
||||
expect(payload.prompt_cache_retention).toBe("24h");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user