-
Notifications
You must be signed in to change notification settings - Fork 46
feat: add Bedrock Mantle API format support for harness #1412
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { ConfigIO, findConfigRoot } from '../../../lib'; | ||
| import { | ||
| AgentNameSchema, | ||
| BedrockApiFormatSchema, | ||
| BuildTypeSchema, | ||
| DatasetNameSchema, | ||
| DatasetSchemaTypeSchema, | ||
|
|
@@ -892,6 +893,20 @@ const VALID_HARNESS_TOOLS = [ | |
| const VALID_GATEWAY_OUTBOUND_AUTH = ['awsIam', 'none', 'oauth'] as const; | ||
|
|
||
| export function validateAddHarnessOptions(options: AddHarnessCliOptions): ValidationResult { | ||
| if (options.apiFormat) { | ||
| const validFormats = BedrockApiFormatSchema.options; | ||
| if (!validFormats.includes(options.apiFormat as (typeof validFormats)[number])) { | ||
| return { | ||
| valid: false, | ||
| error: `Invalid API format: ${options.apiFormat}. Use ${validFormats.join(', ')}`, | ||
| }; | ||
| } | ||
| const provider = options.modelProvider ?? 'bedrock'; | ||
| if (provider !== 'bedrock') { | ||
| return { valid: false, error: '--api-format is only supported for the bedrock provider' }; | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
+896
to
+909
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should extract the common validation logic across create/add into a single util. I see that create/add harness validations have diverged, something to fix later. |
||
| if (options.tools) { | ||
| const toolNames = options.tools.split(',').map(s => s.trim()); | ||
| for (const tool of toolNames) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { validateCreateHarnessOptions } from '../harness-validate'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('validateCreateHarnessOptions', () => { | ||
| const validOptions = { | ||
| name: 'MyHarness', | ||
| modelProvider: 'bedrock', | ||
| modelId: 'anthropic.claude-v2', | ||
| }; | ||
|
|
||
| describe('apiFormat validation', () => { | ||
| it('accepts valid apiFormat for bedrock provider', () => { | ||
| const result = validateCreateHarnessOptions({ ...validOptions, apiFormat: 'responses' }); | ||
| expect(result.valid).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts chat_completions format', () => { | ||
| const result = validateCreateHarnessOptions({ ...validOptions, apiFormat: 'chat_completions' }); | ||
| expect(result.valid).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts converse_stream format', () => { | ||
| const result = validateCreateHarnessOptions({ ...validOptions, apiFormat: 'converse_stream' }); | ||
| expect(result.valid).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects invalid apiFormat value', () => { | ||
| const result = validateCreateHarnessOptions({ ...validOptions, apiFormat: 'invalid_format' }); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.error).toContain('Invalid API format'); | ||
| }); | ||
|
|
||
| it('rejects apiFormat for non-bedrock provider', () => { | ||
| const result = validateCreateHarnessOptions({ | ||
| ...validOptions, | ||
| modelProvider: 'open_ai', | ||
| apiKeyArn: 'arn:aws:secretsmanager:us-east-1:123:secret:key', | ||
| apiFormat: 'responses', | ||
| }); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.error).toContain('only supported for the bedrock provider'); | ||
| }); | ||
|
|
||
| it('passes when apiFormat is not specified', () => { | ||
| const result = validateCreateHarnessOptions(validOptions); | ||
| expect(result.valid).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { CONFIG_DIR } from '../../../lib'; | ||
| import type { HarnessModelProvider, NetworkMode } from '../../../schema'; | ||
| import type { BedrockApiFormat, HarnessModelProvider, NetworkMode } from '../../../schema'; | ||
| import { harnessPrimitive } from '../../primitives/registry'; | ||
| import { type ProgressCallback, createProject } from './action'; | ||
| import type { CreateResult } from './types'; | ||
|
|
@@ -12,6 +12,7 @@ export interface CreateHarnessProjectOptions { | |
| cwd: string; | ||
| modelProvider: HarnessModelProvider; | ||
| modelId: string; | ||
| apiFormat?: BedrockApiFormat; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my own understanding, why do we nest API format under model configuration in some places (eg), but not in others (above). From Harness API perspective, API format will always be nested under the model provider configuration since different model providers support a different set of API formats. |
||
| apiKeyArn?: string; | ||
| skipMemory?: boolean; | ||
| containerUri?: string; | ||
|
|
@@ -57,6 +58,7 @@ export async function createProjectWithHarness(options: CreateHarnessProjectOpti | |
| name: options.name, | ||
| modelProvider: options.modelProvider, | ||
| modelId: options.modelId, | ||
| apiFormat: options.apiFormat, | ||
| apiKeyArn: options.apiKeyArn, | ||
| containerUri: options.containerUri, | ||
| dockerfilePath: options.dockerfilePath, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { APP_DIR, ConfigIO, type Result, findConfigRoot } from '../../lib'; | ||
| import type { | ||
| BedrockApiFormat, | ||
| HarnessGatewayOutboundAuth, | ||
| HarnessModelProvider, | ||
| HarnessSpec, | ||
|
|
@@ -27,6 +28,7 @@ export interface AddHarnessOptions { | |
| name: string; | ||
| modelProvider: HarnessModelProvider; | ||
| modelId: string; | ||
| apiFormat?: BedrockApiFormat; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be extensible for non-Bedrock model providers? For example, Harness now supports OpenAI with responses and chat completions. |
||
| apiKeyArn?: string; | ||
| systemPrompt?: string; | ||
| skipMemory?: boolean; | ||
|
|
@@ -149,6 +151,7 @@ export class HarnessPrimitive extends BasePrimitive<AddHarnessOptions, Removable | |
| model: { | ||
| provider: options.modelProvider, | ||
| modelId: options.modelId, | ||
| ...(options.apiFormat && { apiFormat: options.apiFormat }), | ||
| ...(options.apiKeyArn && { apiKeyArn: options.apiKeyArn }), | ||
| }, | ||
| tools, | ||
|
|
@@ -345,6 +348,7 @@ export class HarnessPrimitive extends BasePrimitive<AddHarnessOptions, Removable | |
| .option('--name <name>', 'Harness name (start with letter, alphanumeric + underscores, max 48 chars)') | ||
| .option('--model-provider <provider>', 'Model provider: bedrock, open_ai, gemini') | ||
| .option('--model-id <id>', 'Model ID (e.g., anthropic.claude-3-5-sonnet-20240620-v1:0)') | ||
| .option('--api-format <format>', 'API format for Bedrock: converse_stream, responses, chat_completions') | ||
| .option('--api-key-arn <arn>', 'API key ARN for non-Bedrock providers') | ||
| .option('--container <uri-or-path>', 'Container image URI or path to a Dockerfile') | ||
| .option('--no-memory', 'Skip auto-creating memory') | ||
|
|
@@ -390,6 +394,7 @@ export class HarnessPrimitive extends BasePrimitive<AddHarnessOptions, Removable | |
| name?: string; | ||
| modelProvider?: string; | ||
| modelId?: string; | ||
| apiFormat?: string; | ||
| apiKeyArn?: string; | ||
| container?: string; | ||
| memory?: boolean; | ||
|
|
@@ -454,16 +459,21 @@ export class HarnessPrimitive extends BasePrimitive<AddHarnessOptions, Removable | |
| process.exit(1); | ||
| } | ||
|
|
||
| const { DEFAULT_MODEL_IDS } = await import('../tui/screens/harness/types'); | ||
| const { DEFAULT_BEDROCK_MANTLE_MODEL_ID, DEFAULT_MODEL_IDS } = | ||
| await import('../tui/screens/harness/types'); | ||
| const provider = (cliOptions.modelProvider ?? 'bedrock') as HarnessModelProvider; | ||
| const modelId = cliOptions.modelId ?? DEFAULT_MODEL_IDS[provider]; | ||
| const isMantleFormat = | ||
| cliOptions.apiFormat === 'responses' || cliOptions.apiFormat === 'chat_completions'; | ||
| const modelId = | ||
| cliOptions.modelId ?? (isMantleFormat ? DEFAULT_BEDROCK_MANTLE_MODEL_ID : DEFAULT_MODEL_IDS[provider]); | ||
|
|
||
| const containerOption = this.parseContainerFlag(cliOptions.container); | ||
|
|
||
| const result = await this.add({ | ||
| name: cliOptions.name, | ||
| modelProvider: provider, | ||
| modelId, | ||
| apiFormat: cliOptions.apiFormat as BedrockApiFormat | undefined, | ||
| apiKeyArn: cliOptions.apiKeyArn, | ||
| containerUri: containerOption.containerUri, | ||
| dockerfilePath: containerOption.dockerfilePath, | ||
|
|
||
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.
Maybe out of scope for this PR, but OpenAI also supports responses/chat completions API formats