Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/integrations/brands/tencent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineBrand({
label: 'Tencent',
canonicalVendorId: 'openai',
defaultCapabilities: {
supportsVision: true,
supportsVision: false,
supportsStreaming: true,
supportsFunctionCalling: true,
supportsJsonMode: true,
Expand Down
6 changes: 3 additions & 3 deletions src/integrations/models/tencent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ export default [
label: 'Tencent HY3',
brandId: 'tencent',
vendorId: 'openai',
classification: ['chat', 'reasoning', 'vision', 'coding'],
classification: ['chat', 'reasoning', 'coding'],
defaultModel: 'tencent/hy3',
capabilities: {
supportsVision: true,
supportsVision: false,
supportsStreaming: true,
supportsFunctionCalling: true,
supportsJsonMode: true,
supportsReasoning: true,
supportsPreciseTokenCount: false,
},
contextWindow: 262_144,
maxOutputTokens: 65_536,
maxOutputTokens: 131_072,
}),
]
41 changes: 41 additions & 0 deletions src/integrations/tencent.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, test } from 'bun:test'

import {
getCatalogEntriesForRoute,
getModel,
} from './index.js'
import { resolveModelRuntimeLimits } from './runtimeMetadata.js'

describe('Tencent HY3 descriptor', () => {
test('exposes the verified HY3 capabilities and limits to gateway catalogs', () => {
const model = getModel('tencent/hy3')

expect(model).toBeDefined()
expect(model).toMatchObject({
id: 'tencent/hy3',
classification: ['chat', 'reasoning', 'coding'],
contextWindow: 262_144,
maxOutputTokens: 131_072,
capabilities: {
supportsVision: false,
supportsStreaming: true,
supportsFunctionCalling: true,
supportsJsonMode: true,
supportsReasoning: true,
},
})

const catalogEntry = getCatalogEntriesForRoute('gitlawb-opengateway').find(
entry => entry.apiName === 'tencent/hy3',
)
expect(catalogEntry?.modelDescriptorId).toBe(model?.id)

expect(
resolveModelRuntimeLimits({
model: 'tencent/hy3',
baseUrl: 'https://opengateway.gitlawb.com/v1',
processEnv: {},
}),
).toEqual({ contextWindow: 262_144, maxOutputTokens: 131_072 })
})
})
78 changes: 77 additions & 1 deletion src/services/api/openaiShim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9920,14 +9920,15 @@ function makeJsonChatCompletion(body: Record<string, unknown>): Response {

async function collectFallbackEvents(
body: Record<string, unknown>,
model = 'fake-model',
): Promise<Array<Record<string, unknown>>> {
const previousFetch = globalThis.fetch
globalThis.fetch = (async () => makeJsonChatCompletion(body)) as unknown as FetchType
try {
const client = createOpenAIShimClient({}) as OpenAIShimClient
const result = await client.beta.messages
.create({
model: 'fake-model',
model,
messages: [{ role: 'user', content: 'hi' }],
max_tokens: 64,
stream: true,
Expand Down Expand Up @@ -10145,6 +10146,81 @@ test('JSON fallback: recovers raw-text tool call into tool_use block', async ()

})

test('JSON fallback: recovers Tencent HY3 text tool calls into tool_use blocks', async () => {
const events = await collectFallbackEvents({
id: 'chatcmpl-json-hy3',
model: 'tencent/hy3',
choices: [
{
message: {
role: 'assistant',
content:
'<tool_call:call_hy3>TaskCreate\n subject: Verify HY3\n description: Run the live test\n</tool_call:call_hy3>',
},
finish_reason: 'stop',
},
],
}, 'tencent/hy3')
const toolStart = events.find(
event =>
event.type === 'content_block_start' &&
typeof event.content_block === 'object' &&
event.content_block !== null &&
(event.content_block as Record<string, unknown>).type === 'tool_use',
) as { content_block?: Record<string, unknown> } | undefined
expect(toolStart?.content_block).toMatchObject({
type: 'tool_use',
name: 'TaskCreate',
})
const jsonDelta = events.find(
event =>
event.type === 'content_block_delta' &&
typeof event.delta === 'object' &&
event.delta !== null &&
(event.delta as Record<string, unknown>).type === 'input_json_delta',
) as { delta?: { partial_json?: string } } | undefined
expect(JSON.parse(jsonDelta?.delta?.partial_json ?? '')).toEqual({
subject: 'Verify HY3',
description: 'Run the live test',
})
const stopEvent = events.find(e => e.type === 'message_delta') as
| { delta?: { stop_reason?: string } }
| undefined
expect(stopEvent?.delta?.stop_reason).toBe('tool_use')
})

test('JSON fallback: preserves HY3-looking text for non-Tencent model names', async () => {
const text =
'<tool_call:example>TaskCreate\nsubject: merely a documentation example\n</tool_call:example>'
const events = await collectFallbackEvents({
id: 'chatcmpl-json-non-tencent-hy3',
model: 'other/hy3-documentation',
choices: [
{
message: { role: 'assistant', content: text },
finish_reason: 'stop',
},
],
}, 'other/hy3-documentation')
const toolStart = events.find(
event =>
event.type === 'content_block_start' &&
typeof event.content_block === 'object' &&
event.content_block !== null &&
(event.content_block as Record<string, unknown>).type === 'tool_use',
)
const textDelta = events.find(
event =>
event.type === 'content_block_delta' &&
typeof event.delta === 'object' &&
event.delta !== null &&
(event.delta as Record<string, unknown>).type === 'text_delta',
) as { delta?: { text?: string } } | undefined

expect(toolStart).toBeUndefined()
expect(textDelta?.delta?.text).toBe(text)
})

test('JSON fallback: empty tool_calls array does not block raw-text recovery', async () => {
// tool_calls: [] is truthy; it must be treated as "no structured tool calls"
// so the raw "Tool calls requested" recovery still runs.
Expand Down
Loading