文件

Text generation(Beta)

Service: agent.api.yating.tw/v1/

用於知識問答與對話。


Single round

Request

URL: /textGenerations
Method: POST

Header

Name Type Info
*key String Bearer {key}

Body

Name Type Info
*model String general_v2_7b_4bit, taiwan_llama_v2_7b_4bit
*inputs int Inputs 至多放十個。
prompt 總長度至多
512 tokens,計算方式是:
一個中文字算一個token
英文一個 wordpiece 算一個token,例如embedding算三個 (em, bed, ding)
maxTokens, optional, int, range from 1 to 2048. To limit text generation token length.
minTokens, optional, int, range from 1 to 2048. Please note that minTokenLen should not larger than maxTokenLen.
** for English,
You can think of tokens as pieces of words used for natural language processing. For English text, 1 token is approximately 4 characters or 0.75 words. As a point of reference, the collected works of Shakespeare are about 900,000 words or 1.2M tokens

Example

{
  "model": "general_v2_7b_4bit",
  "inputs": [
    {
      "prompt": "小明把蘋果給小王,小王給小美。問:蘋果最後在誰手上?"
    }
  ]
}

Response

Name Type Info
data String
data.text String
data.index Int
usage String Total tokens generated in this request.

Example

{
   "data":[
      {
         "text":"小美",
         "index":0
      }
   ],
   "usage":{
      "promptTokens":5,
      "generationTokens":7,
      "totalTokens":12
   }
}

Chat

curl --location 'https://agent.api.yating.tw/v1/textGenerations/chat' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Your Key\
--data '{
    "model": "general_v2_7b_4bit",
    "system": "你是有用的助手",
    "prompt": "你可以做什麼?",
    "history": [{"user":"你是誰?","assistant":"我是雅婷,是由台灣人工智慧實驗室所開發的助理"}],
    "maxTokens": 512,
    "repetitionPenalty": 1.1
}'