-
Notifications
You must be signed in to change notification settings - Fork 2.8k
10935 Add Harmony Provider #10936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ajgreyling
wants to merge
4
commits into
RooCodeInc:main
Choose a base branch
from
ajgreyling:10935-add-harmony-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,363
−6
Draft
10935 Add Harmony Provider #10936
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,66 @@ | ||
| import type { ModelInfo } from "../model.js" | ||
|
|
||
| /** | ||
| * Harmony-compatible API provider types and models | ||
| * | ||
| * Harmony is an open response format specification for GPT-OSS models | ||
| * that enables structured output with separate reasoning and answer channels. | ||
| * | ||
| * @see https://developers.openai.com/cookbook/articles/openai-harmony | ||
| * @see https://github.com/openai/harmony | ||
| */ | ||
|
|
||
| /** | ||
| * Supported Harmony model identifiers | ||
| * | ||
| * - gpt-oss-20b: 20B parameter open-weight model, optimal for speed | ||
| * - gpt-oss-120b: 120B parameter open-weight model, optimal for quality | ||
| * | ||
| * Both models support: | ||
| * - 128,000 token context window | ||
| * - Reasoning effort levels (low, medium, high) | ||
| * - Streaming responses | ||
| * - Function calling | ||
| */ | ||
| export type HarmonyModelId = "gpt-oss-20b" | "gpt-oss-120b" | ||
|
|
||
| /** | ||
| * Default Harmony model | ||
| * @default "gpt-oss-20b" - Balanced model for general use | ||
| */ | ||
| export const harmonyDefaultModelId: HarmonyModelId = "gpt-oss-20b" | ||
|
|
||
| /** | ||
| * Harmony model definitions and capabilities | ||
| * | ||
| * All Harmony models support: | ||
| * - 128,000 token context window for comprehensive codebase analysis | ||
| * - Reasoning effort levels: low, medium, high | ||
| * - Streaming responses for real-time feedback | ||
| * - Function calling for tool integration | ||
| * - OpenAI-compatible API interface | ||
| */ | ||
| export const harmonyModels: Record<HarmonyModelId, ModelInfo> = { | ||
| "gpt-oss-20b": { | ||
| maxTokens: 8192, | ||
| contextWindow: 128000, | ||
| supportsImages: false, | ||
| supportsPromptCache: false, | ||
| supportsReasoningEffort: ["low", "medium", "high"], | ||
| inputPrice: 0, | ||
| outputPrice: 0, | ||
| description: | ||
| "GPT-OSS 20B: 20 billion parameter open-weight model. Optimized for fast inference with 128K context window.", | ||
| }, | ||
| "gpt-oss-120b": { | ||
| maxTokens: 8192, | ||
| contextWindow: 128000, | ||
| supportsImages: false, | ||
| supportsPromptCache: false, | ||
| supportsReasoningEffort: ["low", "medium", "high"], | ||
| inputPrice: 0, | ||
| outputPrice: 0, | ||
| description: | ||
| "GPT-OSS 120B: 120 billion parameter open-weight model. Higher quality reasoning with 128K context window.", | ||
| }, | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,109 @@ | ||
| // npx vitest run src/api/providers/__tests__/harmony-edge-cases.spec.ts | ||
| // Integration tests for Harmony API edge cases | ||
| // Run with: HARMONY_API_KEY=your-key HARMONY_BASE_URL=your-base-url npx vitest run --run api/providers/__tests__/harmony-edge-cases.spec.ts | ||
|
|
||
| import { describe, it, expect, beforeEach, vi } from "vitest" | ||
| import OpenAI from "openai" | ||
|
|
||
| const isIntegrationTest = !!process.env.HARMONY_API_KEY && !!process.env.HARMONY_BASE_URL | ||
| const skipIfNoApi = isIntegrationTest ? describe : describe.skip | ||
|
|
||
| skipIfNoApi("Harmony API Edge Cases (Integration Tests)", () => { | ||
| let client: OpenAI | ||
|
|
||
| beforeEach(() => { | ||
| const apiKey = process.env.HARMONY_API_KEY || "sk-placeholder" | ||
| const baseURL = process.env.HARMONY_BASE_URL | ||
| if (!baseURL) { | ||
| throw new Error("HARMONY_BASE_URL environment variable is required for integration tests") | ||
| } | ||
| client = new OpenAI({ baseURL, apiKey }) | ||
| }) | ||
|
|
||
| it("should handle large input (testing context window)", async () => { | ||
| const largeInput = "Summarize this text: " + "Lorem ipsum dolor sit amet. ".repeat(500) | ||
| const response = await client.chat.completions.create({ | ||
| model: "gpt-oss-20b", | ||
| messages: [{ role: "user", content: largeInput }], | ||
| max_tokens: 100, | ||
| }) | ||
|
|
||
| expect(response.choices).toHaveLength(1) | ||
| expect(response.choices[0].message.content).toBeTruthy() | ||
| expect(response.usage?.prompt_tokens).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("should handle conversation with multiple messages", async () => { | ||
| const response = await client.chat.completions.create({ | ||
| model: "gpt-oss-20b", | ||
| messages: [ | ||
| { role: "user", content: "What is your name?" }, | ||
| { role: "assistant", content: "I'm Claude, an AI assistant." }, | ||
| { role: "user", content: "What can you help me with?" }, | ||
| ], | ||
| max_tokens: 100, | ||
| }) | ||
|
|
||
| expect(response.choices).toHaveLength(1) | ||
| expect(response.choices[0].message.content).toBeTruthy() | ||
| }) | ||
|
|
||
| it("should return proper error for invalid API key", async () => { | ||
| const baseURL = process.env.HARMONY_BASE_URL | ||
| if (!baseURL) { | ||
| throw new Error("HARMONY_BASE_URL environment variable is required") | ||
| } | ||
| const badClient = new OpenAI({ | ||
| baseURL, | ||
| apiKey: "invalid-key-12345", | ||
| }) | ||
|
|
||
| await expect( | ||
| badClient.chat.completions.create({ | ||
| model: "gpt-oss-20b", | ||
| messages: [{ role: "user", content: "Test" }], | ||
| }), | ||
| ).rejects.toThrow() | ||
| }) | ||
|
|
||
| it("should return proper error for unknown model", async () => { | ||
| await expect( | ||
| client.chat.completions.create({ | ||
| model: "unknown-model-xyz", | ||
| messages: [{ role: "user", content: "Test" }], | ||
| }), | ||
| ).rejects.toThrow() | ||
| }) | ||
|
|
||
| it("should list available models", async () => { | ||
| const models = await client.models.list() | ||
|
|
||
| expect(models.data).toBeDefined() | ||
| expect(Array.isArray(models.data)).toBe(true) | ||
| if (models.data.length > 0) { | ||
| expect(models.data[0].id).toBeTruthy() | ||
| } | ||
| }) | ||
|
|
||
| it("should handle high temperature (creative output)", async () => { | ||
| const response = await client.chat.completions.create({ | ||
| model: "gpt-oss-20b", | ||
| messages: [{ role: "user", content: "Generate a creative story starter in one sentence" }], | ||
| temperature: 1.5, | ||
| max_tokens: 100, | ||
| }) | ||
|
|
||
| expect(response.choices[0].message.content).toBeTruthy() | ||
| }) | ||
|
|
||
| it("should handle zero temperature (deterministic)", async () => { | ||
| const response = await client.chat.completions.create({ | ||
| model: "gpt-oss-20b", | ||
| messages: [{ role: "user", content: "What is 2+2?" }], | ||
| temperature: 0, | ||
| max_tokens: 50, | ||
| }) | ||
|
|
||
| expect(response.choices[0].message.content).toBeTruthy() | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
packageManagerversion change frompnpm@10.8.1topnpm@10.28.1appears unrelated to the Harmony provider feature. Consider reverting this change or submitting it as a separate PR to keep the feature scope focused.Fix it with Roo Code or mention @roomote and request a fix.