カスタム LLM の入力と出力の形式を
生成 AI コントローラー 理解するには、トランスフォーマースクリプトを作成する必要があります。トランスフォーマーレコードを作成すると、編集中にガイドとして使用できるコードとコメントが提供されます。これらのスクリプトは、モデルによって解釈される予想される要求オブジェクトと応答オブジェクトに依存します。
たとえば、 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);