Text Inference API
Function
Processes text inference.
This API is scheduled for deprecation. The OpenAI API is recommended.
Format
Operation type: POST
URL: https://{ip}:{port}/generate
Replace {ip} and {port} with the IP address and port number of the service plane, that is, ipAddress and port.
Request Parameters
Parameter |
Mandatory/Optional |
Description |
Value |
|
|---|---|---|---|---|
inputs |
Mandatory |
Indicates the inference request content. The value is of the string type for a single-modal text model and of the list type for a multi-modal model. |
|
|
- |
type |
Optional |
Indicates the inference request content type. |
Instructions for using multimedia files:
NOTE:
Security warning:
|
text |
Optional |
Indicates that the inference request content is text. |
The value cannot be empty. Both Chinese and English are supported. |
|
image_url |
Optional |
Indicates that the inference request content is an image. |
Local JPG, PNG, JPEG, and Base64-encoded JPG images can be imported in URL format. Both HTTP and HTTPS protocols are supported. Currently, the maximum size of an image is 40 MB. |
|
video_url |
Optional |
Indicates that the inference request content is a video. |
Local MP4, AVI, and WMV videos can be imported in URL format. Both HTTP and HTTPS protocols are supported. Currently, the maximum size of a video file is 512 MB. |
|
audio_url |
Optional |
The inference request content is audio. |
Local MP3, WAV, and FLAC audio files can be imported in URL format. Both HTTP and HTTPS protocols are supported. Currently, the maximum size of an audio file is 40 MB. |
|
parameters |
Optional |
Indicates parameters related to model inference postprocessing. |
- |
|
- |
decoder_input_details |
Optional |
Indicates whether to return the token ID of the inference request text. |
The value is of the Boolean type. The default value is false. |
details |
Optional |
Indicates whether to return the detailed inference output result. According to the TGI 0.9.4 API behavior, if either decoder_input_details or details is set to true, all details are returned. |
The value is of the Boolean type. The default value is false. |
|
do_sample |
Optional |
Indicates whether to perform sampling. |
The value is of the Boolean type. If this parameter is not passed, other postprocessing parameters determine whether sampling should be performed.
|
|
max_new_tokens |
Optional |
Indicates the maximum number of tokens that can be generated during inference. The number of generated tokens is also affected by the maxIterTimes parameter in the configuration file. The number of inference tokens is less than or equal to the value of Min(maxIterTimes, max_new_tokens). |
The value is of the int type. The value range is (0, 2147483647]. The default value is 20. |
|
repetition_penalty |
Optional |
Uses repetition penalty to reduce the probability of duplicate fragments during text generation. It penalizes previously generated text, making the model more inclined to choose new, non-repeated content. |
The value is of the float type. The default value is 1.0. The value must be greater than 0.0.
It is recommended that the maximum value be set to 2.0. The value depends on the model. |
|
return_full_text |
Optional |
Indicates whether to add the inference request text (inputs) before the inference result. |
The value is of the Boolean type. The default value is false.
|
|
seed |
Optional |
Indicates the random seed of the inference process. The same seed value ensures the reproducibility of the inference result, and different seed values improve the randomness of the inference result. |
The value is of the uint64_t type. The value range is (0, 18446744073709551615]. If this parameter is not passed, the system generates a random seed value. When the value of seed is close to the maximum value, a warning is generated, which does not affect normal use. To delete the warning, decrease the value of seed. |
|
temperature |
Optional |
Controls the randomness of generation. Higher values produce more diversified outputs. |
The value is of the float type. The value is greater than 1e-6. The default value is 1.0. A larger value indicates greater randomness of the result. You are advised to use a value greater than or equal to 0.001. If the value is less than 0.001, the text quality may be poor. It is recommended that the maximum value be set to 2.0. The value depends on the model. |
|
top_k |
Optional |
Controls the vocabulary range considered during model generation. Only k candidate words with the highest probability are selected. |
The value is of the uint32_t type. The value range is (0, 2147483647].
|
|
top_p |
Optional |
Controls the vocabulary range considered during model generation and selects candidate words using the cumulative probability until it exceeds a given threshold. This parameter can also control the diversity of generated results. |
The value is of the float type. The value range is (1e-6, 1.0). If this field is not set, 1.0 is used by default, indicating that this operation is not performed. However, you cannot set this field to 1.0. |
|
truncate |
Optional |
Truncates the number of tokens to the value specified by this parameter after tokenization is performed on the input text and reads the truncated n tokens. If the value of this field is greater than or equal to the number of tokens, this field is invalid. |
The value is of the uint32_t type. The value range is (0, 2147483647]. If the field is not set, 0 is used by default, indicating that this operation is not performed. However, you cannot set this field to 0. |
|
typical_p |
Optional |
Specifies the decoding output probability distribution exponent. Currently, postprocessing is not supported. |
The value is of the float type. The value range is (0.0, 1.0]. The default value is 1.0. |
|
watermark |
Optional |
Indicates whether to add a model watermark. Currently, postprocessing is not supported. |
The value is of the Boolean type. The default value is false.
|
|
stop |
Optional |
Indicates the text for stopping inference. By default, the output result does not contain the stop word list text. |
The value is of the List[string] or string type. The default value is null.
This parameter is not supported in the PD disaggregation scenario. |
|
adapter_id |
Optional |
Indicates the LoRA weight used for inference, that is, LoRA ID. |
The value is of the string type. The default value is None. The value contains a maximum of 256 characters, including letters, digits, periods (.), hyphens (-), underscores (_), and slashes (/). This parameter is not supported in the PD disaggregation scenario. |
|
Usage Example
Request example:
POST https://{ip}:{port}/generate
Request body:
- Single-modal text model:
{ "inputs": "My name is Olivier and I", "parameters": { "decoder_input_details": true, "details": true, "do_sample": true, "max_new_tokens": 20, "repetition_penalty": 1.03, "return_full_text": false, "seed": null, "temperature": 0.5, "top_k": 10, "top_p": 0.95, "truncate": null, "typical_p": 0.5, "watermark": false, "stop": null, "adapter_id": "None" } } - Multimodal mode:
Change the value of image_url as needed.
{ "inputs": [ {"type": "text", "text": "My name is Olivier and I"}, { "type": "image_url", "image_url": "/xxxx/test.png" } ], "parameters": { "decoder_input_details": true, "details": true, "do_sample": true, "max_new_tokens": 20, "repetition_penalty": 1.03, "return_full_text": false, "seed": null, "temperature": 0.5, "top_k": 10, "top_p": 0.95, "truncate": null, "typical_p": 0.5, "watermark": false, "stop": null, "adapter_id": "None" } }
Response example:
{
"details": {
"finish_reason": "length",
"generated_tokens": 1,
"prefill": [{
"id": 0,
"logprob":null,
"special": null,
"text": "test"
}],
"prompt_tokens": 74,
"seed": 42,
"tokens": [{
"id": 0,
"logprob": null,
"special": null,
"text": "test"
}]
},
"generated_text": "am a Frenchman living in the UK. I have been working as an IT consultant for "
}
Output Description
Return Value |
Type |
Description |
||
|---|---|---|---|---|
details |
Object |
Inference details result. If either decoder_input_details or details in the request is true, the details result is returned. |
||
- |
finish_reason |
String |
End cause.
|
|
generated_tokens |
Integer |
Number of tokens in the inference result. Total number of tokens in the Prefill and Decode inference results. When the maximum inference length of a request is the value of maxIterTimes, the value of generated_tokens in the response of the Decode node is the value of maxIterTimes plus 1, that is, the number of first tokens in the Prefill inference result is added. |
||
prefill |
List[token] |
If the request parameter decoder_input_details is set to true, the tokens after the inference request text detokenization are returned. By default, the token list is empty. |
||
- |
id |
Integer |
Token ID. |
|
logprob |
Float |
Probability logarithm, which can be empty (the probability value of the first token cannot be calculated). This parameter is not supported currently. By default, null is returned. |
||
special |
Bool |
Whether the token is special. If special is true, the token can be ignored during connection. This parameter is not supported currently. By default, null is returned. |
||
text |
String |
Text corresponding to the token. This parameter is not supported currently. By default, null is returned. |
||
prompt_tokens |
Integer |
Token length corresponding to the prompt text entered by a user. |
||
seed |
Integer |
The seed value of the inference request is returned. If seed is not specified in the request, the seed value randomly generated by the system is returned. |
||
tokens |
List[token] |
All tokens of the inference result. |
||
- |
id |
Integer |
Token ID. |
|
logprob |
Logarithmic probability |
This parameter is not supported currently. By default, null is returned. |
||
special |
Bool |
Whether the token is special. If special is true, the token can be ignored during connection. This parameter is not supported currently. By default, null is returned. |
||
text |
String |
Text corresponding to the token. This parameter is not supported currently. By default, null is returned. |
||
generated_text |
String |
Returned inference result. |
||