跳到主要内容

タイプセーフ- TypeSafe Documentation

  • System One API Reference TypeSafeは、System One API を通じて Jev などの意思決定モデルを提供します。TypeSafeDecisionModelを実装しますDecisionModelその上に API があります。 同じ API は他のサーバーでも実装されています。たとえば、 OpenRouter および推論サーバーなど SGLangはオープンモデルを走らせています。 TypeSafeDecisionModel は、ベース URL を設定することで、いずれの URL でも使用できます (below を参照)。
备注

この統合は実験的なものであり、将来のリリースでは変更される可能性があります。

Maven の依存関係​

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-typesafe</artifactId>
<version>1.23.0-beta33</version>
</dependency>

使用法​

DecisionModel decisionModel = TypeSafeDecisionModel.builder()
.apiKey(System.getenv("TYPESAFE_API_KEY"))
.modelName("jev-1.13.0")
.build();

DecisionRequest request = DecisionRequest.builder()
.input("Help! My payouts have been failing for 3 days.")
.question("team", ChoiceQuestion.builder()
.text("Which team should handle this ticket?")
.option("billing", "Payments, payouts, invoices, refunds")
.option("support", "Problems using the product")
.build())
.question("urgent", YesNoQuestion.from("Does this need attention today?"))
.build();

DecisionResponse response = decisionModel.decide(request);

ChoiceAnswer team = response.choice("team");
YesNoAnswer urgent = response.yesNo("urgent");

すべての質問タイプと回答の使用方法については、Decision Models チュートリアルを参照してください。

構成​

TypeSafeDecisionModel decisionModel = TypeSafeDecisionModel.builder()
.apiKey(...) // required for api.typesafe.ai, optional for other servers
.modelName(...) // required here or on each request (otherwise decide() fails), e.g. "jev-1.13.0"
.baseUrl(...) // defaults to "https://api.typesafe.ai"
.apiPath(...) // path of the System One endpoint, relative to baseUrl; defaults to "v1/systemone"
.timeout(...) // defaults to the HTTP client builder's timeouts, otherwise 15s connect / 60s read
.maxRetries(...) // retries after the first attempt; defaults to 2
.customHeaders(...) // additional HTTP headers, as a Map or a Supplier<Map>
.customParameters(...) // additional parameters in the JSON body, see "Custom parameters" below
.listeners(...) // DecisionModelListeners, see Observability in the Decision Models tutorial
.logRequests(...) // defaults to false
.logResponses(...) // defaults to false
.logger(...) // an alternate SLF4J logger for requests and responses
.httpClientBuilder(...) // see below
.build();

利用可能なモデルは TypeSafe documentation にリストされています。 jev-latest などのエイリアスはいつでも新しいバージョンに移行できます。運用環境では、修正バージョンを使用してください。 HTTP クライアントは httpClientBuilder(...) を使用してカスタマイズできます。Customizable HTTP Client を参照してください。 decide() と decideAsync() の両方がサポートされています。 このモデルは、YesNoQuestion、ChoiceQuestion、ScaleQuestion の質問タイプをサポートしています。 TypeSafe のドキュメントでは、はい/いいえの質問は「noul」質問と呼ばれ、スケール質問は「スコア」と呼ばれます。 質問であり、その入力は「状態」と呼ばれます。説明付きのスケール レベル (level(label, description)) は次のとおりです。 label および description を持つオブジェクトとして送信されます。 API はテキストのみを受け入れます。テキストの内容はテキストとして送信され、画像は UnsupportedFeatureException をスローします。 APIを呼び出さずに。会話 (inputMessages(...)) は transcript、{"messages": [...]} として;その中の画像は UnsupportedFeatureException。 選択の信頼度および回答のスケールはサーバーによって計算されます。 回答はリクエストに対して検証されます: 不足している回答、間違ったタイプの回答、選択されていないオプション 提供される、0 から 1 の範囲外の確率、またはレベル外のスケール平均がスローされる InvalidDecisionResponseException。確率が報告されていないスケール回答のレベルの確率は 0 になります。 入力と質問は、構成したサーバーに送信されます。ホスト型サービスを使用する場合は、そのデータを確認してください 処理および保存期間については、Data protection を参照してください。

カスタムパラメータTypeSafeDecisionModel がまだサポートしていないパラメータを送信するには、customParameters(...) で設定します。それは​

すべてのリクエストの JSON 本文に追加されます。

DecisionModel decisionModel = TypeSafeDecisionModel.builder()
.apiKey(System.getenv("TYPESAFE_API_KEY"))
.modelName("jev-latest")
.customParameters(Map.of("parameter_name", "value"))
.build();

単一リクエストのカスタム パラメータを設定するには、TypeSafeDecisionRequestParameters を使用します。空でない場合は、 ビルダーに設定されたカスタム パラメータを置き換えます (マージされません)。

DecisionRequest request = DecisionRequest.builder()
.input(...)
.question(...)
.parameters(TypeSafeDecisionRequestParameters.builder()
.customParameters(Map.of("parameter_name", "another value"))
.build())
.build();

値はそのまま JSON に書き込まれるため、Map 値は JSON オブジェクトになり、String は文字列のままになります。 LangChain4j が送信するパラメーターと同じ名前のカスタム パラメーター (model など) で置き換えられます。選択するには モデルでは modelName(...) を使用します。model カスタム パラメーターは modelName() またはどのリスナーにも反映されません。 受け取ります。回答は常に DecisionRequest の質問に対して読み取られるため、questions や state。 別の意思決定モデルのパラメーター クラスを TypeSafeDecisionModel に渡すと、次のエラーが発生して失敗します。 IllegalArgumentException。 DecisionRequestParameters.builder()、すべてに共通のパラメータのみを持ちます。 意思決定モデルは、あらゆるモデルで機能します。

他のサーバーSystem One API を実装するサーバーは、ベース URL を設定することで使用できます。リクエストはベース URL に送信されます​

API パスが続きます。デフォルトは v1/systemone です。サーバーが別のパスで API を公開する場合は、次のように設定します。 apiPath(...)。たとえば、OpenRouter の場合は次のようになります。

DecisionModel decisionModel = TypeSafeDecisionModel.builder()
.baseUrl("https://openrouter.ai/api")
.apiKey(System.getenv("OPENROUTER_API_KEY"))
.modelName("typesafe/jev-1.13")
.build();

のためにOllamaもこの API を実装しているので、使用しますOllamaDecisionModel代わりに、画像をサポートし、Ollama を プロバイダー。 ローカルサーバーとセルフホストサーバーは通常、API キーを必要としません。 GPU がないと、リクエストに数秒かかる可能性があるため、次のことを考慮してください。 長いtimeout(...)。 TypeSafeDecisionModel は TypeSafe API と OpenRouter でテストされています。 サーバーごとに適用される制限 (オプションの最大数など) が異なる場合があります。 信頼度の計算方法と回答の質: 小規模モデルと汎用言語モデル 意思決定モデルとして提供されるモデルは、通常、専用の意思決定モデルよりも精度が低く、決定力も低くなります。 使用するサーバーのドキュメントを確認し、独自のデータに基づいて答えを評価してください。 ベース URL が何であれ、モデルは、リスナーやメトリックなどでプロバイダーとして ModelProvider.TYPESAFE を報告します。