ドキュメント
エージェントフロー
インテグレーション
テキスト埋め込み
トークン化
モデル情報
エージェントフロー
インテグレーション
テキスト埋め込み
トークン化
モデル情報
基本
チャットの操作
LLMとのチャット会話を表すためのAPI
model.respond()、model.applyPromptTemplate()、またはmodel.act()のようなSDKメソッドは、入力としてチャットパラメータを受け取ります。SDKでチャットを表すには、いくつかの方法があります。
.respond()メソッドを使用したチャットの例を以下に示します。
const prediction = model.respond([
{ role: "system", content: "You are a resident AI philosopher." },
{ role: "user", content: "What is the meaning of life?" },
]);
チャットに単一のユーザーメッセージしかない場合は、単一の文字列を使用してチャットを表すことができます。.respondメソッドを使用した例を以下に示します。
const prediction = model.respond("What is the meaning of life?");
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で利用可能です。