(newFormat: Pipe)
| 29 | * @returns The converted old pipe format. |
| 30 | */ |
| 31 | export function toOldPipeFormat(newFormat: Pipe): PipeOld { |
| 32 | const [providerString, modelName] = newFormat.model.split(':'); |
| 33 | |
| 34 | const systemMessage = newFormat.messages.find( |
| 35 | m => m.role === 'system' && !m.name |
| 36 | ); |
| 37 | const safetyMessage = newFormat.messages.find( |
| 38 | m => m.role === 'system' && m.name === 'safety' |
| 39 | ); |
| 40 | const ragMessage = newFormat.messages.find( |
| 41 | m => m.role === 'system' && m.name === 'rag' |
| 42 | ); |
| 43 | const jsonMessage = newFormat.messages.find( |
| 44 | m => m.role === 'system' && m.name === 'json' |
| 45 | ); |
| 46 | |
| 47 | return { |
| 48 | name: newFormat.name, |
| 49 | description: newFormat.description, |
| 50 | status: newFormat.status, |
| 51 | config: { |
| 52 | meta: { |
| 53 | stream: newFormat.stream, |
| 54 | json: newFormat.json, |
| 55 | store: newFormat.store, |
| 56 | moderate: newFormat.moderate |
| 57 | }, |
| 58 | model: { |
| 59 | name: modelName, |
| 60 | provider: getProvider(providerString), |
| 61 | params: { |
| 62 | top_p: newFormat.top_p, |
| 63 | max_tokens: newFormat.max_tokens, |
| 64 | temperature: newFormat.temperature, |
| 65 | presence_penalty: newFormat.presence_penalty, |
| 66 | frequency_penalty: newFormat.frequency_penalty, |
| 67 | stop: newFormat.stop |
| 68 | }, |
| 69 | tool_choice: newFormat.tool_choice, |
| 70 | parallel_tool_calls: newFormat.parallel_tool_calls |
| 71 | }, |
| 72 | prompt: { |
| 73 | system: |
| 74 | systemMessage?.content || 'You are a helpful AI assistant.', |
| 75 | opening: 'Welcome to Langbase. Prompt away!', |
| 76 | safety: safetyMessage?.content || '', |
| 77 | messages: newFormat.messages |
| 78 | .filter(m => m.role !== 'system') |
| 79 | .map(m => ({ role: m.role, content: m.content ?? '' })), |
| 80 | variables: newFormat.variables, |
| 81 | json: jsonMessage?.content || '', |
| 82 | rag: ragMessage?.content || '' |
| 83 | }, |
| 84 | tools: newFormat.tools, |
| 85 | memorysets: newFormat.memory.map(memory => memory.name) |
| 86 | } |
| 87 | }; |
| 88 | } |
nothing calls this directly
no test coverage detected