생성형 AI 컨트롤러 사용자 지정 LLM의 입력 및 출력 형식을 이해하려면 변환기 스크립트를 작성해야 합니다. 변환기 기록을 만들면 편집하는 동안 가이드로 사용할 수 있는 코드와 주석이 제공됩니다. 이러한 스크립트는 모델에 의해 해석되는 예상 요청 및 응답 객체에 따라 달라집니다.
예를 들어 요청 구조는 Azure OpenAI 다음 스크립트와 같습니다.
{"messages": [{"role":"user", "content":"Summarize the following text: <<content>>"}], "max_tokens": 800, "temperature": 0.7}
해당 요청 구조에 대한 요청 변환기 스크립트는 다음 스크립트입니다.
(function(inputs) {
/* write code here to construct the request body and any custom headers needed using the inputs object.
inputs structure: {
prompt_data: object,
request_data: object
} */
var requestData = inputs.request_data;
var promptData = inputs.prompt_data;
var prompt = promptData.prompt;
var model = promptData.model;
// construct body using the inputs
var body = {
messages: [{
"role": "user",
"content": prompt
}],
max_tokens: parseInt(promptData.max_tokens),
temperature: parseInt(promptData.temperature)
};
//construct headers using the inputs
var headers = {};
return {
body: body,
headers: headers
};
})(inputs);
의
Azure OpenAI 응답 구조는 다음 스크립트와 같습니다.
{
"choices": [{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "<<response>>",
"role": "assistant"
}
}],
"created": 1714994995,
"id": "chatcmpl-9LqpXeLVXDAi6kciPfLeIDjmALeea",
"model": "gpt-35-turbo-16k",
"object": "chat.completion",
"usage": {
"completion_tokens": 47,
"prompt_tokens": 70,
"total_tokens": 117
}
}
이러한 응답 구조로 인해 응답 변환기 스크립트는 다음 스크립트와 같습니다.
(function(inputs) {
/* write code here to transform the llm response into an array of text responses, using the inputs object
inputs structure: {
prompt_data: object,
request_data: object,
response_body: string,
response_headers: string
} */
var requestData = inputs.request_data;
var promptData = inputs.prompt_data;
var responseBody = JSON.parse(inputs.response_body);
gs.info("response : " + inputs.response_body);
var responseTexts = [];
// write code here to populate the responseTexts array.
responseTexts.push(responseBody.choices[0].message.content);
return responseTexts;
})(inputs);