昇腾社区首页
中文
注册

使用兼容TGI 0.9.4版本的接口

本章节以文本推理接口和流式推理接口为例介绍接口调用,其他接口的调用方法请参见兼容TGI 0.9.4版本接口章节。

文本推理接口

接口名

文本推理接口

URL

https://{服务IP地址}:{端口号}/generate

请求类型

POST

请求示例

curl -H "Accept: application/json" -H "Content-type: application/json" --cacert ca.pem --cert client.pem  --key client.key.pem -X POST -d '{
    "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"
    }
}' https://127.0.0.1:1025/generate

返回示例

{
    "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 "
}

流式推理接口

接口名

流式推理接口

URL

https://{服务IP地址}:{端口号}/generate_stream

请求类型

POST

请求示例

curl -H "Accept: application/json" -H "Content-type: application/json" --cacert ca.pem --cert client.pem  --key client.key.pem -X POST -d '{
    "inputs": "My name is Olivier and I",
    "parameters": {
        "decoder_input_details": false,
        "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"
    }
}' https://127.0.0.1:1025/generate_stream

返回示例

data: {"token":{"id":13,"text":"\n","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":26626,"text":"Jan","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":300,"text":"et","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":3732,"text":" makes","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":395,"text":" $","logprob":null,"special":null},"generated_text":null,"details":null}

……

data: {"token":{"id":395,"text":" $","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":29896,"text":"1","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":29896,"text":"1","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":29947,"text":"8","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":29889,"text":".","logprob":null,"special":null},"generated_text":null,"details":null}

data: {"token":{"id":2,"text":"","logprob":null,"special":null},"generated_text":"\nJanet makes $104 a day at the farmers' market.\nThe number of eggs that Janet sells at the farmers' market each day is 16 - 3 - 4 = 7.\nShe makes $2 for each egg that she sells.\nThe total amount that she makes is $2 * 7 = $14.\nThe total amount that she makes is $14 + $104 = $118.\nThe total amount that she makes is $118.","details":{"prompt_tokens":74,"finish_reason":"eos_token","generated_tokens":116,"seed":8756727004129248931}}