* Applies structured output configuration to a payload based on model capabilities. * Uses native json_schema for supported models, falls back to json_object with prompt instructions.
( targetPayload: any, messages: any[], responseFormat: any, model: string )
| 39 | * Uses native json_schema for supported models, falls back to json_object with prompt instructions. |
| 40 | */ |
| 41 | async function applyResponseFormat( |
| 42 | targetPayload: any, |
| 43 | messages: any[], |
| 44 | responseFormat: any, |
| 45 | model: string |
| 46 | ): Promise<any[]> { |
| 47 | const useNative = await supportsNativeStructuredOutputs(model) |
| 48 | |
| 49 | if (useNative) { |
| 50 | logger.info('Using native structured outputs for Together model', { model }) |
| 51 | targetPayload.response_format = { |
| 52 | type: 'json_schema', |
| 53 | json_schema: { |
| 54 | name: responseFormat.name || 'response_schema', |
| 55 | schema: responseFormat.schema || responseFormat, |
| 56 | }, |
| 57 | } |
| 58 | return messages |
| 59 | } |
| 60 | |
| 61 | logger.info('Using json_object mode with prompt instructions for Together model', { model }) |
| 62 | const schema = responseFormat.schema || responseFormat |
| 63 | const schemaInstructions = generateSchemaInstructions(schema, responseFormat.name) |
| 64 | targetPayload.response_format = { type: 'json_object' } |
| 65 | return [...messages, { role: 'user', content: schemaInstructions }] |
| 66 | } |
| 67 | |
| 68 | export const togetherProvider: ProviderConfig = { |
| 69 | id: 'together', |
no test coverage detected