HuggingFace REST Client

Predict Request

var request = PredictRequest.builder()
    .question("My Question")
    .style("my-custom-style")
    .model('model-to-use') // this is optional. This line can be omitted and the server will use the default model
    .chunk(new Chunk("chunk-1", "First chunk of text for the prediction"))
    .chunk(new Chunk("chunk-2", "Second chunk of text for the prediction"))
    .build();

var result = client.predict(request);

A model can be specified. If so, then it will be passed as part of the request to the HuggingFace server. This is optional however. If no model is provided then the server will use the default one.

The result will return 200 for the status code and the corresponding iterable prediction:

[
  {
    "answer": "prediction",
    "probability": 1.0,
    "start_logit": 4.5558319091796875,
    "end_logit": 4.782039165496826,
    "id": "chunk-1",
    "highlight": "First chunk of text for the <span class=\"my-custom-style\">prediction</span>"
  },
  {
    "answer": "",
    "probability": 1.0,
    "start_logit": 0,
    "end_logit": 0,
    "id": "chunk-2"
  }
]

Summarize Request

var request = SummarizeRequest.builder()
    .maxLength(200) // Optional. This line can be omitted and the builder will add the default value: 200
    .minLength(0) // Optional. This line can be omitted and the builder will add the default value: 0
    .cleanUp(true) // Optional. This line can be omitted and the builder will add the default value: true
    .model("model-to-use") // Optional. This line can be omitted and the server will use the default model
    .chunk(new Chunk("chunk-1", "First chunk of text for the summary"))
    .chunk(new Chunk("chunk-2", "Second chunk of text for the summary"))
    .build();

var result = client.summarize(request);

A model can be specified. If so, then it will be passed as part of the request to the HuggingFace server. This is optional; however, if no model is provided then the server will use the default one.

The result will return 200 for the status code and the corresponding iterable summary:

[
  {
    "summary_text": "First summary",
    "id": "chunk-1"
  },
  {
    "summary_text": "Second summary",
    "id": "chunk-2"
  }
]

Analyze Sentiment Request

var request = AnalyzeSentimentRequest.builder()
    .function("function-to-use") // Optional. This line can be omitted and the server will use the default function
    .model("model-to-use") // Optional. This line can be omitted and the server will use the default model
    .chunk(new Chunk("chunk-1", "First chunk of text for the sentiment analysis"))
    .chunk(new Chunk("chunk-2", "Second chunk of text for the sentiment analysis"))
    .build();

var result = client.analyzeSentiment(request);

A model can be specified. If so, then it will be passed as part of the request to the HuggingFace server. This is optional; however, if no model is provided then the server will use the default one.

The result will return 200 for the status code and the corresponding iterable sentiment:

[
  {
    "label": "First label",
    "score": 1,
    "id": "chunk-1"
  },
  {
    "label": "Second label",
    "score": 1,
    "id": "chunk-2"
  }
]

Classify Request

var request = ClassifyRequest.builder()
    .hypothesisTemplate("template-to-use") // Optional. This line can be omitted and the builder will add the default value: "This example is {}."
    .multiLabel(false) // Optional. This line can be omitted and the builder will add the default value: false
    .label("label-1")
    .label("label-2")
    .label("label-3")
    .model("model-to-use") // Optional. This line can be omitted and the server will use the default model
    .chunk(new Chunk("chunk-1", "First chunk of text for the sentiment analysis"))
    .chunk(new Chunk("chunk-2", "Second chunk of text for the sentiment analysis"))
    .build();

var result = client.classify(request);

A model can be specified. If so, then it will be passed as part of the request to the HuggingFace server. This is optional; however, if no model is provided then the server will use the default one.

The result will return 200 for the status code and the corresponding iterable classification:

[
  {
    "labels": ["label-1", "label-2", "label-3"],
    "scores": [1, 0.5, 0],
    "id": "chunk-1"
  },
  {
    "labels": ["label-3", "label-1", "label-2"],
    "scores": [1, 0.5, 0],
    "id": "chunk-2"
  }
]

©2024 Pureinsights Technology Corporation