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
+29
-1
@@ -2,6 +2,7 @@ import { Type } from "typebox";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { stream as streamOpenAICompletions } from "../src/api/openai-completions.ts";
|
||||
import type { AssistantMessage, Model, Tool } from "../src/types.ts";
|
||||
import { normalizeContext } from "../src/utils/transcript.ts";
|
||||
|
||||
const mockState = vi.hoisted(() => ({
|
||||
chunkSets: [] as unknown[][],
|
||||
@@ -96,7 +97,9 @@ function toolCallChunk(): unknown {
|
||||
}
|
||||
|
||||
async function runOpenAICompletionsStream(messages: AssistantMessage[] = []): Promise<AssistantMessage> {
|
||||
return await streamOpenAICompletions(model(), { messages, tools: [readTool] }, { apiKey: "test" }).result();
|
||||
return await streamOpenAICompletions(model(), normalizeContext({ messages, tools: [readTool] }), {
|
||||
apiKey: "test",
|
||||
}).result();
|
||||
}
|
||||
|
||||
function getAssistantPayload(payload: unknown): { reasoning?: unknown; reasoning_details?: unknown } | undefined {
|
||||
@@ -249,3 +252,28 @@ describe("openai-completions reasoning_details streaming", () => {
|
||||
expect(getAssistantPayload(mockState.payloads[1])?.reasoning_details).toEqual(expectedReasoningDetails);
|
||||
});
|
||||
});
|
||||
|
||||
describe("openai-completions reasoning and content in one delta", () => {
|
||||
beforeEach(() => {
|
||||
mockState.chunkSets = [];
|
||||
mockState.payloads = [];
|
||||
});
|
||||
|
||||
// https://github.com/earendil-works/pi/issues/10926
|
||||
it("places thinking before text when one delta carries reasoning_content and content", async () => {
|
||||
mockState.chunkSets = [[chunk({ role: "assistant", reasoning_content: "thinking", content: "answer" }, "stop")]];
|
||||
|
||||
const assistantMessage = await runOpenAICompletionsStream();
|
||||
expect(assistantMessage.content).toEqual([
|
||||
{ type: "thinking", thinking: "thinking", thinkingSignature: "reasoning_content" },
|
||||
{ type: "text", text: "answer" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("places thinking before text when one delta carries reasoning_details and content", async () => {
|
||||
mockState.chunkSets = [[chunk({ reasoning_details: [reasoningDetail], content: "answer" }, "stop")]];
|
||||
|
||||
const assistantMessage = await runOpenAICompletionsStream();
|
||||
expect(assistantMessage.content.map((block) => block.type)).toEqual(["thinking", "text"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user