Custom script Processor
Custom script Processor
Overview
The Custom script
processor allows users to extract specific values from api calls and to customize them using Javascript
Parameters
Each parameter is defined as a key-value pair inside the parameters
section.
script_text
Required: True
Type: string
Defines the javascript callback that will be invoked once an API call will be reach this processor.
The Javascript function executed would be:
function onAPICall(request, response){
//your custom script
return void
}
Example:
- key: script_text
value: |
delete request.headers['secret']
request.body.some_key = btoa(request.body.some_other_key) //convert to base64
request.body.system_prompt += ", answer in spanish"
would generate the following function that will be invoked in runtime
function onAPICall(request, response){
delete request.headers['secret']
request.body.some_key = btoa(request.body.some_other_key) //convert to base64
request.body.system_prompt += ", answer in spanish"
return void
}
Best Practices
- todo1
- todo2
User Custom script Template
Custom script Processor Example
CustomScript:
processor: CustomScript # Specifies the Custom script Processor
parameters:
- key:
value: |
delete request.headers['secret'];
request.body.some_key = btoa(request.body.some_other_key); //convert to base64
request.body.system_prompt += ", answer in spanish";
Use Case
You can use the CustomScript
Processor to monitor calls to convert the message format of OpenAI API calls to anthropic's:
Custom script Processor Example
CustomScript:
processor: CustomScript # Specifies the Custom script Processor
parameters:
- key:
value: |
const originalMessages = request.body.messages;
// Move the first 'system' message into Anthropic's 'system' field, if present
const systemMsg = originalMessages.find(msg => msg.role === 'system');
if (systemMsg) {
request.body.system = systemMsg.content;
}
// Rebuild messages array for Anthropic
// - Typically only user or assistant messages become Anthropic "messages"
// - If you want to keep only user messages, filter by (msg => msg.role === 'user')
const newAnthropicMessages = originalMessages
.filter(msg => msg.role === 'user' || msg.role === 'assistant')
.map(msg => {
return {
role: msg.role,
content: [
{
type: 'text',
text: msg.content
}
]
};
});
request.body.messages = newAnthropicMessages;