ドキュメント

基本

チャットの操作

LLMとのチャット会話を表すためのAPI

model.respond()model.applyPromptTemplate()、またはmodel.act()のようなSDKメソッドは、入力としてチャットパラメータを受け取ります。SDKでチャットを表すには、いくつかの方法があります。

オプション1:メッセージの配列

.respond()メソッドを使用したチャットの例を以下に示します。

const prediction = model.respond([
  { role: "system", content: "You are a resident AI philosopher." },
  { role: "user", content: "What is the meaning of life?" },
]);

オプション2:単一の文字列を入力

チャットに単一のユーザーメッセージしかない場合は、単一の文字列を使用してチャットを表すことができます。.respondメソッドを使用した例を以下に示します。

const prediction = model.respond("What is the meaning of life?");

オプション3:Chatヘルパークラスの使用

より複雑なタスクには、Chatヘルパークラスの使用をお勧めします。チャットを管理するためのさまざまな一般的に使用されるメソッドが提供されています。Chatクラスを使用した例を以下に示します。

const chat = Chat.empty();
chat.append("system", "You are a resident AI philosopher.");
chat.append("user", "What is the meaning of life?");

const prediction = model.respond(chat);

Chat.fromメソッドを使用して、Chatオブジェクトをすばやく構築することもできます。

const chat = Chat.from([
  { role: "system", content: "You are a resident AI philosopher." },
  { role: "user", content: "What is the meaning of life?" },
]);

このページのソースはGitHubで利用可能です。