Class SystemOneClient

java.lang.Object
org.springframework.ai.systemone.api.SystemOneClient

public class SystemOneClient extends Object
The System One client. Wraps SystemOneApi with a default model, a retry policy and the typed exceptions, and stitches the x-typesafe-request-id header onto the response so it travels with the data it describes.

 SystemOneClient client = SystemOneClient.builder().apiKey(apiKey).build();

 SystemOneResponse response = client.systemOne(SystemOneRequest.builder()
         .state(Map.of("message", "Help! My payouts have been failing for 3 days."))
         .question("is_urgent", Noul.of("Does this convey urgency?"))
         .question("department", Choice.builder()
                 .instructions("Which team should handle this?")
                 .option("billing", "Payments, invoicing, refunds")
                 .option("technical", "Bugs, outages, integrations")
                 .build())
         .build());

 if (response.noulValue("is_urgent") > 0.8) {
     escalate(response.choiceValue("department"));
 }
 
Every question of a call is answered against the same state in parallel, so asking several narrow questions costs little more than asking one, and each answer stays independently thresholdable.
Since:
2.1.0
Author:
Christian Tzolov
  • Constructor Details

    • SystemOneClient

      public SystemOneClient(SystemOneApi systemOneApi, String defaultModel, org.springframework.core.retry.RetryTemplate retryTemplate)
      Creates a client over an API instance.
      Parameters:
      systemOneApi - the transport layer
      defaultModel - the model applied to a request that does not name one
      retryTemplate - how transient failures are retried; see SystemOneRetryUtils
  • Method Details

    • systemOne

      public SystemOneResponse systemOne(String state, Map<String,? extends Question> questions)
      Answers questions about a text state.
      Parameters:
      state - the content to evaluate
      questions - the questions, keyed by the names their answers will carry
      Returns:
      the answers
    • systemOne

      public SystemOneResponse systemOne(Map<String,?> state, Map<String,? extends Question> questions)
      Answers questions about a structured state. Naming the parts of the state is the recommended shape: it lets a question point at a field instead of relying on position inside a serialized blob.

      The fields and questions are sent in the maps' iteration order, which can change an answer. Pass ordered maps, or use JsonContent.object(Object...) for the state and SystemOneRequest.builder() for the questions: Map.of iterates in an order that changes with every JVM run.

      Parameters:
      state - the content to evaluate
      questions - the questions, keyed by the names their answers will carry
      Returns:
      the answers
    • systemOne

      public SystemOneResponse systemOne(List<?> state, Map<String,? extends Question> questions)
      Answers questions about a sequence, for example the turns of a conversation.
      Parameters:
      state - the content to evaluate
      questions - the questions, keyed by the names their answers will carry
      Returns:
      the answers
    • systemOne

      public SystemOneResponse systemOne(JsonContent state, Map<String,? extends Question> questions)
      Answers questions about a state.
      Parameters:
      state - the content to evaluate
      questions - the questions, keyed by the names their answers will carry
      Returns:
      the answers
    • systemOne

      public SystemOneResponse systemOne(SystemOneRequest request)
      Answers a fully assembled request, applying the client's default model when the request does not name one.
      Parameters:
      request - the request
      Returns:
      the answers, carrying the request id from the response headers
    • listModels

      public List<ModelMetadata> listModels()
      Lists the models available to the account.
      Returns:
      the models, never null
    • defaultModel

      public String defaultModel()
      Returns:
      the model applied to requests that do not name one
    • builder

      public static SystemOneClient.Builder builder()
      Returns:
      a new builder