xhigh.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { describe, expect, it } from "vitest";
  2. import { getModel } from "../src/models.ts";
  3. import { stream } from "../src/stream.ts";
  4. import type { Context, Model } from "../src/types.ts";
  5. function makeContext(): Context {
  6. return {
  7. messages: [
  8. {
  9. role: "user",
  10. content: `What is ${(Math.random() * 100) | 0} + ${(Math.random() * 100) | 0}? Think step by step.`,
  11. timestamp: Date.now(),
  12. },
  13. ],
  14. };
  15. }
  16. describe.skipIf(!process.env.OPENAI_API_KEY)("xhigh reasoning", () => {
  17. describe("codex-max (supports xhigh)", () => {
  18. // Note: codex models only support the responses API, not chat completions
  19. it("should work with openai-responses", async () => {
  20. const model = getModel("openai", "gpt-5.1-codex-max");
  21. const s = stream(model, makeContext(), { reasoningEffort: "xhigh" });
  22. let hasThinking = false;
  23. for await (const event of s) {
  24. if (event.type === "thinking_start" || event.type === "thinking_delta") {
  25. hasThinking = true;
  26. }
  27. }
  28. const response = await s.result();
  29. expect(response.stopReason, `Error: ${response.errorMessage}`).toBe("stop");
  30. expect(response.content.some((b) => b.type === "text")).toBe(true);
  31. expect(hasThinking || response.content.some((b) => b.type === "thinking")).toBe(true);
  32. });
  33. });
  34. describe("gpt-5-mini (does not support xhigh)", () => {
  35. it("should error with openai-responses when using xhigh", async () => {
  36. const model = getModel("openai", "gpt-5-mini");
  37. const s = stream(model, makeContext(), { reasoningEffort: "xhigh" });
  38. for await (const _ of s) {
  39. // drain events
  40. }
  41. const response = await s.result();
  42. expect(response.stopReason).toBe("error");
  43. expect(response.errorMessage).toContain("xhigh");
  44. });
  45. it("should error with openai-completions when using xhigh", async () => {
  46. const { compat: _compat, ...baseModel } = getModel("openai", "gpt-5-mini");
  47. void _compat;
  48. const model: Model<"openai-completions"> = {
  49. ...baseModel,
  50. api: "openai-completions",
  51. };
  52. const s = stream(model, makeContext(), { reasoningEffort: "xhigh" });
  53. for await (const _ of s) {
  54. // drain events
  55. }
  56. const response = await s.result();
  57. expect(response.stopReason).toBe("error");
  58. expect(response.errorMessage).toContain("xhigh");
  59. });
  60. });
  61. });