You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

template_advanced_chat.ja.mdx 62KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # 高度なチャットアプリ API
  4. チャットアプリケーションはセッションの持続性をサポートしており、以前のチャット履歴を応答のコンテキストとして使用できます。これは、チャットボットやカスタマーサービス AI などに適用できます。
  5. <div>
  6. ### ベース URL
  7. <CodeGroup title="コード" targetCode={props.appDetail.api_base_url}>
  8. ```javascript
  9. ```
  10. </CodeGroup>
  11. ### 認証
  12. サービス API は `API-Key` 認証を使用します。
  13. <i>**API キーはサーバー側に保存し、クライアント側で共有または保存しないことを強くお勧めします。API キーの漏洩は深刻な結果を招く可能性があります。**</i>
  14. すべての API リクエストには、以下のように `Authorization`HTTP ヘッダーに API キーを含めてください:
  15. <CodeGroup title="コード">
  16. ```javascript
  17. Authorization: Bearer {API_KEY}
  18. ```
  19. </CodeGroup>
  20. </div>
  21. ---
  22. <Heading
  23. url='/chat-messages'
  24. method='POST'
  25. title='チャットメッセージを送信'
  26. name='#Send-Chat-Message'
  27. />
  28. <Row>
  29. <Col>
  30. チャットアプリケーションにリクエストを送信します。
  31. ### リクエストボディ
  32. <Properties>
  33. <Property name='query' type='string' key='query'>
  34. ユーザー入力/質問内容
  35. </Property>
  36. <Property name='inputs' type='object' key='inputs'>
  37. アプリによって定義されたさまざまな変数値の入力を許可します。
  38. `inputs`パラメータには複数のキー/値ペアが含まれ、各キーは特定の変数に対応し、各値はその変数の特定の値です。
  39. 変数がファイルタイプの場合、以下の`files`で説明されているキーを持つオブジェクトを指定します。
  40. デフォルト`{}`
  41. </Property>
  42. <Property name='response_mode' type='string' key='response_mode'>
  43. 応答の返却モードを指定します。サポートされているモード:
  44. - `streaming` ストリーミングモード(推奨)、SSE([サーバー送信イベント](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events))を通じてタイプライターのような出力を実装します。
  45. - `blocking` ブロッキングモード、実行完了後に結果を返します。(プロセスが長い場合、リクエストが中断される可能性があります)
  46. Cloudflareの制限により、リクエストは100秒後に返答なしで中断されます。
  47. </Property>
  48. <Property name='user' type='string' key='user'>
  49. ユーザー識別子、エンドユーザーの身元を定義するために使用され、統計のために使用されます。
  50. アプリケーション内で開発者によって一意に定義されるべきです。サービス API は WebApp によって作成された会話を共有しません。
  51. </Property>
  52. <Property name='conversation_id' type='string' key='conversation_id'>
  53. 会話ID、以前のチャット記録に基づいて会話を続けるには、以前のメッセージのconversation_idを渡す必要があります。
  54. </Property>
  55. <Property name='files' type='array[object]' key='files'>
  56. ファイルリスト、テキストの理解と質問への回答を組み合わせたファイルの入力に適しており、モデルがビジョン機能をサポートしている場合にのみ利用可能です。
  57. - `type` (string) サポートされているタイプ:
  58. - `document` ('TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB')
  59. - `image` ('JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG')
  60. - `audio` ('MP3', 'M4A', 'WAV', 'WEBM', 'AMR')
  61. - `video` ('MP4', 'MOV', 'MPEG', 'MPGA')
  62. - `custom` (他のファイルタイプ)
  63. - `transfer_method` (string) 転送方法、画像URLの場合は`remote_url` / ファイルアップロードの場合は`local_file`
  64. - `url` (string) 画像URL(転送方法が`remote_url`の場合)
  65. - `upload_file_id` (string) アップロードされたファイルID、事前にファイルアップロードAPIを通じて取得する必要があります(転送方法が`local_file`の場合)
  66. </Property>
  67. <Property name='auto_generate_name' type='bool' key='auto_generate_name'>
  68. タイトルを自動生成、デフォルトは`true`。
  69. `false`に設定すると、会話のリネームAPIを呼び出し、`auto_generate`を`true`に設定することで非同期タイトル生成を実現できます。
  70. </Property>
  71. <Property name='trace_id' type='string' key='trace_id'>
  72. (オプション)トレースID。既存の業務システムのトレースコンポーネントと連携し、エンドツーエンドの分散トレーシングを実現するために使用します。指定がない場合、システムが自動的に trace_id を生成します。以下の3つの方法で渡すことができ、優先順位は次のとおりです:<br/>
  73. - Header:HTTPヘッダー <code>X-Trace-Id</code> で渡す(最優先)。<br/>
  74. - クエリパラメータ:URLクエリパラメータ <code>trace_id</code> で渡す。<br/>
  75. - リクエストボディ:リクエストボディの <code>trace_id</code> フィールドで渡す(本フィールド)。<br/>
  76. </Property>
  77. </Properties>
  78. ### 応答
  79. response_modeがブロッキングの場合、CompletionResponseオブジェクトを返します。
  80. response_modeがストリーミングの場合、ChunkCompletionResponseストリームを返します。
  81. ### ChatCompletionResponse
  82. 完全なアプリ結果を返します。`Content-Type`は`application/json`です。
  83. - `event` (string) イベントタイプ、固定で `message`
  84. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  85. - `id` (string) ユニークID
  86. - `message_id` (string) 一意のメッセージID
  87. - `conversation_id` (string) 会話ID
  88. - `mode` (string) アプリモード、`chat`として固定
  89. - `answer` (string) 完全な応答内容
  90. - `metadata` (object) メタデータ
  91. - `usage` (Usage) モデル使用情報
  92. - `retriever_resources` (array[RetrieverResource]) 引用と帰属リスト
  93. - `created_at` (int) メッセージ作成タイムスタンプ、例:1705395332
  94. ### ChunkChatCompletionResponse
  95. アプリによって出力されたストリームチャンクを返します。`Content-Type`は`text/event-stream`です。
  96. 各ストリーミングチャンクは`data:`で始まり、2つの改行文字`\n\n`で区切られます。以下のように表示されます:
  97. <CodeGroup>
  98. ```streaming {{ title: '応答' }}
  99. data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n
  100. ```
  101. </CodeGroup>
  102. ストリーミングチャンクの構造は`event`に応じて異なります:
  103. - `event: message` LLMがテキストチャンクイベントを返します。つまり、完全なテキストがチャンク形式で出力されます。
  104. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  105. - `message_id` (string) 一意のメッセージID
  106. - `conversation_id` (string) 会話ID
  107. - `answer` (string) LLMが返したテキストチャンク内容
  108. - `created_at` (int) 作成タイムスタンプ、例:1705395332
  109. - `event: message_file` メッセージファイルイベント、ツールによって新しいファイルが作成されました
  110. - `id` (string) ファイル一意ID
  111. - `type` (string) ファイルタイプ、現在は"image"のみ許可
  112. - `belongs_to` (string) 所属、ここでは'assistant'のみ
  113. - `url` (string) ファイルのリモートURL
  114. - `conversation_id` (string) 会話ID
  115. - `event: message_end` メッセージ終了イベント、このイベントを受信するとストリーミングが終了したことを意味します。
  116. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  117. - `message_id` (string) 一意のメッセージID
  118. - `conversation_id` (string) 会話ID
  119. - `metadata` (object) メタデータ
  120. - `usage` (Usage) モデル使用情報
  121. - `retriever_resources` (array[RetrieverResource]) 引用と帰属リスト
  122. - `event: tts_message` TTSオーディオストリームイベント、つまり音声合成出力。内容はMp3形式のオーディオブロックで、base64文字列としてエンコードされています。再生時には、base64をデコードしてプレーヤーに入力するだけです。(このメッセージは自動再生が有効な場合にのみ利用可能)
  123. - `task_id` (string) タスクID、リクエスト追跡と以下のストップ応答インターフェースに使用
  124. - `message_id` (string) 一意のメッセージID
  125. - `audio` (string) 音声合成後のオーディオ、base64テキストコンテンツとしてエンコードされており、再生時にはbase64をデコードしてプレーヤーに入力するだけです
  126. - `created_at` (int) 作成タイムスタンプ、例:1705395332
  127. - `event: tts_message_end` TTSオーディオストリーム終了イベント、このイベントを受信するとオーディオストリームが終了したことを示します。
  128. - `task_id` (string) タスクID、リクエスト追跡と以下のストップ応答インターフェースに使用
  129. - `message_id` (string) 一意のメッセージID
  130. - `audio` (string) 終了イベントにはオーディオがないため、これは空の文字列です
  131. - `created_at` (int) 作成タイムスタンプ、例:1705395332
  132. - `event: message_replace` メッセージ内容置換イベント。
  133. 出力内容のモデレーションが有効な場合、内容がフラグ付けされると、このイベントを通じてメッセージ内容がプリセットの返信に置き換えられます。
  134. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  135. - `message_id` (string) 一意のメッセージID
  136. - `conversation_id` (string) 会話ID
  137. - `answer` (string) 置換内容(すべてのLLM返信テキストを直接置き換えます)
  138. - `created_at` (int) 作成タイムスタンプ、例:1705395332
  139. - `event: workflow_started` ワークフローが実行を開始
  140. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  141. - `workflow_run_id` (string) ワークフロー実行の一意ID
  142. - `event` (string) `workflow_started`に固定
  143. - `data` (object) 詳細
  144. - `id` (string) ワークフロー実行の一意ID
  145. - `workflow_id` (string) 関連ワークフローのID
  146. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  147. - `event: node_started` ノード実行が開始
  148. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  149. - `workflow_run_id` (string) ワークフロー実行の一意ID
  150. - `event` (string) `node_started`に固定
  151. - `data` (object) 詳細
  152. - `id` (string) ワークフロー実行の一意ID
  153. - `node_id` (string) ノードのID
  154. - `node_type` (string) ノードのタイプ
  155. - `title` (string) ノードの名前
  156. - `index` (int) 実行シーケンス番号、トレースノードシーケンスを表示するために使用
  157. - `predecessor_node_id` (string) オプションのプレフィックスノードID、キャンバス表示実行パスに使用
  158. - `inputs` (object) ノードで使用されるすべての前のノード変数の内容
  159. - `created_at` (timestamp) 開始のタイムスタンプ、例:1705395332
  160. - `event: node_finished` ノード実行が終了、成功または失敗は同じイベント内で異なる状態で示されます
  161. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  162. - `workflow_run_id` (string) ワークフロー実行の一意ID
  163. - `event` (string) `node_finished`に固定
  164. - `data` (object) 詳細
  165. - `id` (string) ワークフロー実行の一意ID
  166. - `node_id` (string) ノードのID
  167. - `node_type` (string) ノードのタイプ
  168. - `title` (string) ノードの名前
  169. - `index` (int) 実行シーケンス番号、トレースノードシーケンスを表示するために使用
  170. - `predecessor_node_id` (string) オプションのプレフィックスノードID、キャンバス表示実行パスに使用
  171. - `inputs` (object) ノードで使用されるすべての前のノード変数の内容
  172. - `process_data` (json) オプションのノードプロセスデータ
  173. - `outputs` (json) オプションの出力内容
  174. - `status` (string) 実行の状態、`running` / `succeeded` / `failed` / `stopped`
  175. - `error` (string) オプションのエラー理由
  176. - `elapsed_time` (float) オプションの使用される合計秒数
  177. - `execution_metadata` (json) メタデータ
  178. - `total_tokens` (int) オプションの使用されるトークン数
  179. - `total_price` (decimal) オプションの合計コスト
  180. - `currency` (string) オプション、例:`USD` / `RMB`
  181. - `created_at` (timestamp) 開始のタイムスタンプ、例:1705395332
  182. - `event: workflow_finished` ワークフロー実行が終了、成功または失敗は同じイベント内で異なる状態で示されます
  183. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  184. - `workflow_run_id` (string) ワークフロー実行の一意ID
  185. - `event` (string) `workflow_finished`に固定
  186. - `data` (object) 詳細
  187. - `id` (string) ワークフロー実行のID
  188. - `workflow_id` (string) 関連ワークフローのID
  189. - `status` (string) 実行の状態、`running` / `succeeded` / `failed` / `stopped`
  190. - `outputs` (json) オプションの出力内容
  191. - `error` (string) オプションのエラー理由
  192. - `elapsed_time` (float) オプションの使用される合計秒数
  193. - `total_tokens` (int) オプションの使用されるトークン数
  194. - `total_steps` (int) デフォルト0
  195. - `created_at` (timestamp) 開始時間
  196. - `finished_at` (timestamp) 終了時間
  197. - `event: error`
  198. ストリーミングプロセス中に発生する例外はストリームイベントの形式で出力され、エラーイベントを受信するとストリームが終了します。
  199. - `task_id` (string) タスクID、リクエスト追跡と以下のStop Generate APIに使用
  200. - `message_id` (string) 一意のメッセージID
  201. - `status` (int) HTTPステータスコード
  202. - `code` (string) エラーコード
  203. - `message` (string) エラーメッセージ
  204. - `event: ping` 接続を維持するために10秒ごとにpingイベントが発生します。
  205. ### エラー
  206. - 404, 会話が存在しません
  207. - 400, `invalid_param`, 異常なパラメータ入力
  208. - 400, `app_unavailable`, アプリ構成が利用できません
  209. - 400, `provider_not_initialize`, 利用可能なモデル資格情報構成がありません
  210. - 400, `provider_quota_exceeded`, モデル呼び出しクォータが不足しています
  211. - 400, `model_currently_not_support`, 現在のモデルが利用できません
  212. - 400, `completion_request_error`, テキスト生成に失敗しました
  213. - 500, 内部サーバーエラー
  214. </Col>
  215. <Col sticky>
  216. <CodeGroup title="リクエスト" tag="POST" label="/chat-messages" targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "query": "iPhone 13 Pro Maxの仕様は何ですか?",\n "response_mode": "streaming",\n "conversation_id": "",\n "user": "abc-123",\n "files": [\n {\n "type": "image",\n "transfer_method": "remote_url",\n "url": "https://cloud.dify.ai/logo/logo-site.png"\n }\n ]\n}'`}>
  217. ```bash {{ title: 'cURL' }}
  218. curl -X POST '${props.appDetail.api_base_url}/chat-messages' \
  219. --header 'Authorization: Bearer {api_key}' \
  220. --header 'Content-Type: application/json' \
  221. --data-raw '{
  222. "inputs": {},
  223. "query": "eh",
  224. "response_mode": "streaming",
  225. "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
  226. "user": "abc-123"
  227. }'
  228. ```
  229. </CodeGroup>
  230. ### ブロッキングモード
  231. <CodeGroup title="応答">
  232. ```json {{ title: '応答' }}
  233. {
  234. "event": "message",
  235. "task_id": "c3800678-a077-43df-a102-53f23ed20b88",
  236. "id": "9da23599-e713-473b-982c-4328d4f5c78a",
  237. "message_id": "9da23599-e713-473b-982c-4328d4f5c78a",
  238. "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2",
  239. "mode": "chat",
  240. "answer": "iPhone 13 Pro Maxの仕様は次のとおりです:...",
  241. "metadata": {
  242. "usage": {
  243. "prompt_tokens": 1033,
  244. "prompt_unit_price": "0.001",
  245. "prompt_price_unit": "0.001",
  246. "prompt_price": "0.0010330",
  247. "completion_tokens": 128,
  248. "completion_unit_price": "0.002",
  249. "completion_price_unit": "0.001",
  250. "completion_price": "0.0002560",
  251. "total_tokens": 1161,
  252. "total_price": "0.0012890",
  253. "currency": "USD",
  254. "latency": 0.7682376249867957
  255. },
  256. "retriever_resources": [
  257. {
  258. "position": 1,
  259. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  260. "dataset_name": "iPhone",
  261. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  262. "document_name": "iPhone List",
  263. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  264. "score": 0.98457545,
  265. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
  266. }
  267. ]
  268. },
  269. "created_at": 1705407629
  270. }
  271. ```
  272. </CodeGroup>
  273. ### ストリーミングモード
  274. <CodeGroup title="応答">
  275. ```streaming {{ title: '応答' }}
  276. data: {"event": "workflow_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "created_at": 1679586595}}
  277. data: {"event": "node_started", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "created_at": 1679586595}}
  278. data: {"event": "node_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "node_id": "dfjasklfjdslag", "node_type": "start", "title": "Start", "index": 0, "predecessor_node_id": "fdljewklfklgejlglsd", "inputs": {}, "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "execution_metadata": {"total_tokens": 63127864, "total_price": 2.378, "currency": "USD"}, "created_at": 1679586595}}
  279. data: {"event": "workflow_finished", "task_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "workflow_run_id": "5ad498-f0c7-4085-b384-88cbe6290", "data": {"id": "5ad498-f0c7-4085-b384-88cbe6290", "workflow_id": "dfjasklfjdslag", "outputs": {}, "status": "succeeded", "elapsed_time": 0.324, "total_tokens": 63127864, "total_steps": "1", "created_at": 1679586595, "finished_at": 1679976595}}
  280. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " I", "created_at": 1679586595}
  281. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": "'m", "created_at": 1679586595}
  282. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " glad", "created_at": 1679586595}
  283. data: {"event": "message", "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " to", "created_at": 1679586595}
  284. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " meet", "created_at": 1679586595}
  285. data: {"event": "message", "message_id" : "5ad4cb98-f0c7-4085-b384-88c403be6290", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "answer": " you", "created_at": 1679586595}
  286. data: {"event": "message_end", "id": "5e52ce04-874b-4d27-9045-b3bc80def685", "conversation_id": "45701982-8118-4bc5-8e9b-64562b4555f2", "metadata": {"usage": {"prompt_tokens": 1033, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0010330", "completion_tokens": 135, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0002700", "total_tokens": 1168, "total_price": "0.0013030", "currency": "USD", "latency": 1.381760165997548}, "retriever_resources": [{"position": 1, "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb", "dataset_name": "iPhone", "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00", "document_name": "iPhone List", "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a", "score": 0.98457545, "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""}]}}
  287. data: {"event": "tts_message", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"}
  288. data: {"event": "tts_message_end", "conversation_id": "23dd85f3-1a41-4ea0-b7a9-062734ccfaf9", "message_id": "a8bdc41c-13b2-4c18-bfd9-054b9803038c", "created_at": 1721205487, "task_id": "3bf8a0bb-e73b-4690-9e66-4e429bad8ee7", "audio": ""}
  289. ```
  290. </CodeGroup>
  291. </Col>
  292. </Row>
  293. ---
  294. <Heading
  295. url='/files/upload'
  296. method='POST'
  297. title='ファイルアップロード'
  298. name='#file-upload'
  299. />
  300. <Row>
  301. <Col>
  302. メッセージ送信時に使用するファイルをアップロードし、画像とテキストのマルチモーダル理解を可能にします。
  303. アプリケーションでサポートされている形式をサポートします。
  304. アップロードされたファイルは現在のエンドユーザーのみが使用できます。
  305. ### リクエストボディ
  306. このインターフェースは`multipart/form-data`リクエストを必要とします。
  307. - `file` (File) 必須
  308. アップロードするファイル。
  309. - `user` (string) 必須
  310. ユーザー識別子、開発者のルールによって定義され、アプリケーション内で一意でなければなりません。サービス API は WebApp によって作成された会話を共有しません。
  311. ### 応答
  312. アップロードが成功すると、サーバーはファイルの ID と関連情報を返します。
  313. - `id` (uuid) ID
  314. - `name` (string) ファイル名
  315. - `size` (int) ファイルサイズ(バイト)
  316. - `extension` (string) ファイル拡張子
  317. - `mime_type` (string) ファイルの MIME タイプ
  318. - `created_by` (uuid) エンドユーザーID
  319. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  320. ### エラー
  321. - 400, `no_file_uploaded`, ファイルが提供されなければなりません
  322. - 400, `too_many_files`, 現在は 1 つのファイルのみ受け付けます
  323. - 400, `unsupported_preview`, ファイルはプレビューをサポートしていません
  324. - 400, `unsupported_estimate`, ファイルは推定をサポートしていません
  325. - 413, `file_too_large`, ファイルが大きすぎます
  326. - 415, `unsupported_file_type`, サポートされていない拡張子、現在はドキュメントファイルのみ受け付けます
  327. - 503, `s3_connection_failed`, S3 サービスに接続できません
  328. - 503, `s3_permission_denied`, S3 にファイルをアップロードする権限がありません
  329. - 503, `s3_file_too_large`, ファイルが S3 のサイズ制限を超えています
  330. - 500, 内部サーバーエラー
  331. </Col>
  332. <Col sticky>
  333. ### リクエスト例
  334. <CodeGroup title="リクエスト" tag="POST" label="/files/upload" targetCode={`curl -X POST '${props.appDetail.api_base_url}/files/upload' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=image/[png|jpeg|jpg|webp|gif]' \\\n--form 'user=abc-123'`}>
  335. ```bash {{ title: 'cURL' }}
  336. curl -X POST '${props.appDetail.api_base_url}/files/upload' \
  337. --header 'Authorization: Bearer {api_key}' \
  338. --form 'file=@"/path/to/file"'
  339. ```
  340. </CodeGroup>
  341. ### 応答例
  342. <CodeGroup title="応答">
  343. ```json {{ title: '応答' }}
  344. {
  345. "id": "72fa9618-8f89-4a37-9b33-7e1178a24a67",
  346. "name": "example.png",
  347. "size": 1024,
  348. "extension": "png",
  349. "mime_type": "image/png",
  350. "created_by": "6ad1ab0a-73ff-4ac1-b9e4-cdb312f71f13",
  351. "created_at": 1577836800,
  352. }
  353. ```
  354. </CodeGroup>
  355. </Col>
  356. </Row>
  357. ---
  358. <Heading
  359. url='/chat-messages/:task_id/stop'
  360. method='POST'
  361. title='生成を停止'
  362. name='#stop-generatebacks'
  363. />
  364. <Row>
  365. <Col>
  366. ストリーミングモードでのみサポートされています。
  367. ### パス
  368. - `task_id` (string) タスク ID、ストリーミングチャンクの返り値から取得できます
  369. ### リクエストボディ
  370. - `user` (string) 必須
  371. ユーザー識別子、エンドユーザーの身元を定義するために使用され、送信メッセージインターフェースで渡されたユーザーと一致している必要があります。サービス API は WebApp によって作成された会話を共有しません。
  372. ### 応答
  373. - `result` (string) 常に"success"を返します
  374. </Col>
  375. <Col sticky>
  376. ### リクエスト例
  377. <CodeGroup title="リクエスト" tag="POST" label="/chat-messages/:task_id/stop" targetCode={`curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \\\n-H 'Authorization: Bearer {api_key}' \\\n-H 'Content-Type: application/json' \\\n--data-raw '{"user": "abc-123"}'`}>
  378. ```bash {{ title: 'cURL' }}
  379. curl -X POST '${props.appDetail.api_base_url}/chat-messages/:task_id/stop' \
  380. -H 'Authorization: Bearer {api_key}' \
  381. -H 'Content-Type: application/json' \
  382. --data-raw '{
  383. "user": "abc-123"
  384. }'
  385. ```
  386. </CodeGroup>
  387. ### 応答例
  388. <CodeGroup title="応答">
  389. ```json {{ title: '応答' }}
  390. {
  391. "result": "success"
  392. }
  393. ```
  394. </CodeGroup>
  395. </Col>
  396. </Row>
  397. ---
  398. <Heading
  399. url='/messages/:message_id/feedbacks'
  400. method='POST'
  401. title='メッセージフィードバック'
  402. name='#feedbacks'
  403. />
  404. <Row>
  405. <Col>
  406. エンドユーザーはフィードバックメッセージを提供でき、アプリケーション開発者が期待される出力を最適化するのを支援します。
  407. ### パス
  408. <Properties>
  409. <Property name='message_id' type='string' key='message_id'>
  410. メッセージID
  411. </Property>
  412. </Properties>
  413. ### リクエストボディ
  414. <Properties>
  415. <Property name='rating' type='string' key='rating'>
  416. アップボートは`like`、ダウンボートは`dislike`、アップボートの取り消しは`null`
  417. </Property>
  418. <Property name='user' type='string' key='user'>
  419. ユーザー識別子、開発者のルールによって定義され、アプリケーション内で一意でなければなりません。
  420. </Property>
  421. <Property name='content' type='string' key='content'>
  422. メッセージのフィードバックです。
  423. </Property>
  424. </Properties>
  425. ### 応答
  426. - `result` (string) 常に"success"を返します
  427. </Col>
  428. <Col sticky>
  429. <CodeGroup title="リクエスト" tag="POST" label="/messages/:message_id/feedbacks" targetCode={`curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks \\\n --header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "rating": "like",\n "user": "abc-123",\n "content": "message feedback information"\n}'`}>
  430. ```bash {{ title: 'cURL' }}
  431. curl -X POST '${props.appDetail.api_base_url}/messages/:message_id/feedbacks' \
  432. --header 'Authorization: Bearer {api_key}' \
  433. --header 'Content-Type: application/json' \
  434. --data-raw '{
  435. "rating": "like",
  436. "user": "abc-123",
  437. "content": "message feedback information"
  438. }'
  439. ```
  440. </CodeGroup>
  441. <CodeGroup title="応答">
  442. ```json {{ title: '応答' }}
  443. {
  444. "result": "success"
  445. }
  446. ```
  447. </CodeGroup>
  448. </Col>
  449. </Row>
  450. ---
  451. <Heading
  452. url='/app/feedbacks'
  453. method='GET'
  454. title='アプリのメッセージの「いいね」とフィードバックを取得'
  455. name='#app-feedbacks'
  456. />
  457. <Row>
  458. <Col>
  459. アプリのエンドユーザーからのフィードバックや「いいね」を取得します。
  460. ### クエリ
  461. <Properties>
  462. <Property name='page' type='string' key='page'>
  463. (任意)ページ番号。デフォルト値:1
  464. </Property>
  465. </Properties>
  466. <Properties>
  467. <Property name='limit' type='string' key='limit'>
  468. (任意)1ページあたりの件数。デフォルト値:20
  469. </Property>
  470. </Properties>
  471. ### レスポンス
  472. - `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
  473. </Col>
  474. <Col sticky>
  475. <CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>
  476. ```bash {{ title: 'cURL' }}
  477. curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
  478. --header 'Authorization: Bearer {api_key}' \
  479. --header 'Content-Type: application/json'
  480. ```
  481. </CodeGroup>
  482. <CodeGroup title="Response">
  483. ```json {{ title: 'Response' }}
  484. {
  485. "data": [
  486. {
  487. "id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
  488. "app_id": "f252d396-fe48-450e-94ec-e184218e7346",
  489. "conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
  490. "message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
  491. "rating": "like",
  492. "content": "message feedback information-3",
  493. "from_source": "user",
  494. "from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
  495. "from_account_id": null,
  496. "created_at": "2025-04-24T09:24:38",
  497. "updated_at": "2025-04-24T09:24:38"
  498. }
  499. ]
  500. }
  501. ```
  502. </CodeGroup>
  503. </Col>
  504. </Row>
  505. ---
  506. <Heading
  507. url='/messages/{message_id}/suggested'
  508. method='GET'
  509. title='次の推奨質問'
  510. name='#suggested'
  511. />
  512. <Row>
  513. <Col>
  514. 現在のメッセージに対する次の質問の提案を取得します
  515. ### パスパラメータ
  516. <Properties>
  517. <Property name='message_id' type='string' key='message_id'>
  518. メッセージID
  519. </Property>
  520. </Properties>
  521. ### クエリ
  522. <Properties>
  523. <Property name='user' type='string' key='user'>
  524. ユーザー識別子、エンドユーザーの身元を定義するために使用され、統計のために使用されます。
  525. アプリケーション内で開発者によって一意に定義されるべきです。
  526. </Property>
  527. </Properties>
  528. </Col>
  529. <Col sticky>
  530. <CodeGroup title="リクエスト" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested?user=abc-123& \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
  531. ```bash {{ title: 'cURL' }}
  532. curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested?user=abc-123' \
  533. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  534. --header 'Content-Type: application/json' \
  535. ```
  536. </CodeGroup>
  537. <CodeGroup title="応答">
  538. ```json {{ title: '応答' }}
  539. {
  540. "result": "success",
  541. "data": [
  542. "a",
  543. "b",
  544. "c"
  545. ]
  546. }
  547. ```
  548. </CodeGroup>
  549. </Col>
  550. </Row>
  551. ---
  552. <Heading
  553. url='/messages'
  554. method='GET'
  555. title='会話履歴メッセージを取得'
  556. name='#messages'
  557. />
  558. <Row>
  559. <Col>
  560. スクロールロード形式で履歴チャット記録を返し、最初のページは最新の`{limit}`メッセージを返します。つまり、逆順です。
  561. ### クエリ
  562. <Properties>
  563. <Property name='conversation_id' type='string' key='conversation_id'>
  564. 会話ID
  565. </Property>
  566. <Property name='user' type='string' key='user'>
  567. ユーザー識別子、エンドユーザーの身元を定義するために使用され、統計のために使用されます。
  568. アプリケーション内で開発者によって一意に定義されるべきです。
  569. </Property>
  570. <Property name='first_id' type='string' key='first_id'>
  571. 現在のページの最初のチャット記録のID、デフォルトはnullです。
  572. </Property>
  573. <Property name='limit' type='int' key='limit'>
  574. 1回のリクエストで返すチャット履歴メッセージの数、デフォルトは20です。
  575. </Property>
  576. </Properties>
  577. ### 応答
  578. - `data` (array[object]) メッセージリスト
  579. - `id` (string) メッセージID
  580. - `conversation_id` (string) 会話ID
  581. - `inputs` (object) ユーザー入力パラメータ。
  582. - `query` (string) ユーザー入力/質問内容。
  583. - `message_files` (array[object]) メッセージファイル
  584. - `id` (string) ID
  585. - `type` (string) ファイルタイプ、画像の場合はimage
  586. - `url` (string) プレビュー画像URL
  587. - `belongs_to` (string) 所属、userまたはassistant
  588. - `answer` (string) 応答メッセージ内容
  589. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  590. - `feedback` (object) フィードバック情報
  591. - `rating` (string) アップボートは`like` / ダウンボートは`dislike`
  592. - `retriever_resources` (array[RetrieverResource]) 引用と帰属リスト
  593. - `has_more` (bool) 次のページがあるかどうか
  594. - `limit` (int) 返された項目数、入力がシステム制限を超える場合、システム制限数を返します
  595. </Col>
  596. <Col sticky>
  597. <CodeGroup title="リクエスト" tag="GET" label="/messages" targetCode={`curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='\\\n --header 'Authorization: Bearer {api_key}'`}>
  598. ```bash {{ title: 'cURL' }}
  599. curl -X GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id='
  600. --header 'Authorization: Bearer {api_key}'
  601. ```
  602. </CodeGroup>
  603. ### 応答例
  604. <CodeGroup title="応答">
  605. ```json {{ title: '応答' }}
  606. {
  607. "limit": 20,
  608. "has_more": false,
  609. "data": [
  610. {
  611. "id": "a076a87f-31e5-48dc-b452-0061adbbc922",
  612. "conversation_id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  613. "inputs": {
  614. "name": "dify"
  615. },
  616. "query": "iphone 13 pro",
  617. "answer": "iPhone 13 Proは2021年9月24日に発売され、6.1インチのディスプレイと1170 x 2532の解像度を備えています。Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)プロセッサ、6 GBのRAMを搭載し、128 GB、256 GB、512 GB、1 TBのストレージオプションを提供します。カメラは12 MP、バッテリー容量は3095 mAhで、iOS 15を搭載しています。",
  618. "message_files": [],
  619. "feedback": null,
  620. "retriever_resources": [
  621. {
  622. "position": 1,
  623. "dataset_id": "101b4c97-fc2e-463c-90b1-5261a4cdcafb",
  624. "dataset_name": "iPhone",
  625. "document_id": "8dd1ad74-0b5f-4175-b735-7d98bbbb4e00",
  626. "document_name": "iPhone List",
  627. "segment_id": "ed599c7f-2766-4294-9d1d-e5235a61270a",
  628. "score": 0.98457545,
  629. "content": "\"Model\",\"Release Date\",\"Display Size\",\"Resolution\",\"Processor\",\"RAM\",\"Storage\",\"Camera\",\"Battery\",\"Operating System\"\n\"iPhone 13 Pro Max\",\"September 24, 2021\",\"6.7 inch\",\"1284 x 2778\",\"Hexa-core (2x3.23 GHz Avalanche + 4x1.82 GHz Blizzard)\",\"6 GB\",\"128, 256, 512 GB, 1TB\",\"12 MP\",\"4352 mAh\",\"iOS 15\""
  630. }
  631. ],
  632. "created_at": 1705569239,
  633. }
  634. ]
  635. }
  636. ```
  637. </CodeGroup>
  638. </Col>
  639. </Row>
  640. ---
  641. <Heading
  642. url='/conversations'
  643. method='GET'
  644. title='会話を取得'
  645. name='#conversations'
  646. />
  647. <Row>
  648. <Col>
  649. 現在のユーザーの会話リストを取得し、デフォルトで最新の 20 件を返します。
  650. ### クエリ
  651. <Properties>
  652. <Property name='user' type='string' key='user'>
  653. ユーザー識別子、エンドユーザーの身元を定義するために使用され、統計のために使用されます。
  654. アプリケーション内で開発者によって一意に定義されるべきです。
  655. </Property>
  656. <Property name='last_id' type='string' key='last_id'>
  657. (Optional)現在のページの最後の記録のID、デフォルトはnullです。
  658. </Property>
  659. <Property name='limit' type='int' key='limit'>
  660. (Optional)1回のリクエストで返す記録の数、デフォルトは最新の20件です。最大100、最小1。
  661. </Property>
  662. <Property name='sort_by' type='string' key='sort_by'>
  663. (Optional)ソートフィールド、デフォルト:-updated_at(更新時間で降順にソート)
  664. - 利用可能な値:created_at, -created_at, updated_at, -updated_at
  665. - フィールドの前の記号は順序または逆順を表し、"-"は逆順を表します。
  666. </Property>
  667. </Properties>
  668. ### 応答
  669. - `data` (array[object]) 会話のリスト
  670. - `id` (string) 会話ID
  671. - `name` (string) 会話名、デフォルトではLLMによって生成されます。
  672. - `inputs` (object) ユーザー入力パラメータ。
  673. - `introduction` (string) 紹介
  674. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  675. - `updated_at` (timestamp) 更新タイムスタンプ、例:1705395332
  676. - `has_more` (bool)
  677. - `limit` (int) 返されたエントリ数、入力がシステム制限を超える場合、システム制限数が返されます
  678. </Col>
  679. <Col sticky>
  680. <CodeGroup title="リクエスト" tag="GET" label="/conversations" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \\\n --header 'Authorization: Bearer {api_key}'`}>
  681. ```bash {{ title: 'cURL' }}
  682. curl -X GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \
  683. --header 'Authorization: Bearer {api_key}'
  684. ```
  685. </CodeGroup>
  686. <CodeGroup title="応答">
  687. ```json {{ title: '応答' }}
  688. {
  689. "limit": 20,
  690. "has_more": false,
  691. "data": [
  692. {
  693. "id": "10799fb8-64f7-4296-bbf7-b42bfbe0ae54",
  694. "name": "新しいチャット",
  695. "inputs": {
  696. "book": "book",
  697. "myName": "Lucy"
  698. },
  699. "status": "normal",
  700. "created_at": 1679667915,
  701. "updated_at": 1679667915
  702. },
  703. {
  704. "id": "hSIhXBhNe8X1d8Et"
  705. // ...
  706. }
  707. ]
  708. }
  709. ```
  710. </CodeGroup>
  711. </Col>
  712. </Row>
  713. ---
  714. <Heading
  715. url='/conversations/:conversation_id'
  716. method='DELETE'
  717. title='会話を削除'
  718. name='#delete'
  719. />
  720. <Row>
  721. <Col>
  722. 会話を削除します。
  723. ### パス
  724. - `conversation_id` (string) 会話ID
  725. ### リクエストボディ
  726. <Properties>
  727. <Property name='user' type='string' key='user'>
  728. ユーザー識別子、開発者によって定義され、アプリケーション内で一意であることを保証しなければなりません。
  729. </Property>
  730. </Properties>
  731. ### 応答
  732. - `result` (string) 常に"success"を返します
  733. </Col>
  734. <Col sticky>
  735. <CodeGroup title="リクエスト" tag="DELETE" label="/conversations/:conversation_id" targetCode={`curl -X DELETE '${props.appDetail.api_base_url}/conversations/:conversation_id' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "user": "abc-123"\n}'`}>
  736. ```bash {{ title: 'cURL' }}
  737. curl -X DELETE '${props.appDetail.api_base_url}/conversations/{conversation_id}' \
  738. --header 'Content-Type: application/json' \
  739. --header 'Accept: application/json' \
  740. --header 'Authorization: Bearer {api_key}' \
  741. --data '{
  742. "user": "abc-123"
  743. }'
  744. ```
  745. </CodeGroup>
  746. <CodeGroup title="応答">
  747. ```text {{ title: '応答' }}
  748. 204 No Content
  749. ```
  750. </CodeGroup>
  751. </Col>
  752. </Row>
  753. ---
  754. <Heading
  755. url='/conversations/:conversation_id/name'
  756. method='POST'
  757. title='会話の名前を変更'
  758. name='#rename'
  759. />
  760. <Row>
  761. <Col>
  762. ### リクエストボディ
  763. セッションの名前を変更します。セッション名は、複数のセッションをサポートするクライアントでの表示に使用されます。
  764. ### パス
  765. - `conversation_id` (string) 会話ID
  766. <Properties>
  767. <Property name='name' type='string' key='name'>
  768. (Optional)会話の名前。`auto_generate`が`true`に設定されている場合、このパラメータは省略できます。
  769. </Property>
  770. <Property name='auto_generate' type='bool' key='auto_generate'>
  771. (Optional)タイトルを自動生成、デフォルトは`false`
  772. </Property>
  773. <Property name='user' type='string' key='user'>
  774. ユーザー識別子、開発者によって定義され、アプリケーション内で一意であることを保証しなければなりません。
  775. </Property>
  776. </Properties>
  777. ### 応答
  778. - `id` (string) 会話ID
  779. - `name` (string) 会話名
  780. - `inputs` (object) ユーザー入力パラメータ
  781. - `status` (string) 会話状態
  782. - `introduction` (string) 紹介
  783. - `created_at` (timestamp) 作成タイムスタンプ、例:1705395332
  784. - `updated_at` (timestamp) 更新タイムスタンプ、例:1705395332
  785. </Col>
  786. <Col sticky>
  787. <CodeGroup title="リクエスト" tag="POST" label="/conversations/:conversation_id/name" targetCode={`curl -X POST '${props.appDetail.api_base_url}/conversations/:conversation_id/name' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{ \n "name": "", \n "auto_generate": true, \n "user": "abc-123"\n}'`}>
  788. ```bash {{ title: 'cURL' }}
  789. curl -X POST '${props.appDetail.api_base_url}/conversations/{conversation_id}/name' \
  790. --header 'Content-Type: application/json' \
  791. --header 'Authorization: Bearer {api_key}' \
  792. --data-raw '{
  793. "name": "",
  794. "auto_generate": true,
  795. "user": "abc-123"
  796. }'
  797. ```
  798. </CodeGroup>
  799. <CodeGroup title="応答">
  800. ```json {{ title: '応答' }}
  801. {
  802. "id": "cd78daf6-f9e4-4463-9ff2-54257230a0ce",
  803. "name": "チャット vs AI",
  804. "inputs": {},
  805. "status": "normal",
  806. "introduction": "",
  807. "created_at": 1705569238,
  808. "updated_at": 1705569238
  809. }
  810. ```
  811. </CodeGroup>
  812. </Col>
  813. </Row>
  814. ---
  815. <Heading
  816. url='/conversations/:conversation_id/variables'
  817. method='GET'
  818. title='会話変数の取得'
  819. name='#conversation-variables'
  820. />
  821. <Row>
  822. <Col>
  823. 特定の会話から変数を取得します。このエンドポイントは、会話中に取得された構造化データを抽出するのに役立ちます。
  824. ### パスパラメータ
  825. <Properties>
  826. <Property name='conversation_id' type='string' key='conversation_id'>
  827. 変数を取得する会話のID。
  828. </Property>
  829. </Properties>
  830. ### クエリパラメータ
  831. <Properties>
  832. <Property name='user' type='string' key='user'>
  833. ユーザー識別子。開発者によって定義されたルールに従い、アプリケーション内で一意である必要があります。
  834. </Property>
  835. <Property name='last_id' type='string' key='last_id'>
  836. (Optional)現在のページの最後の記録のID、デフォルトはnullです。
  837. </Property>
  838. <Property name='limit' type='int' key='limit'>
  839. (Optional)1回のリクエストで返す記録の数、デフォルトは最新の20件です。最大100、最小1。
  840. </Property>
  841. </Properties>
  842. ### レスポンス
  843. - `limit` (int) ページごとのアイテム数
  844. - `has_more` (bool) さらにアイテムがあるかどうか
  845. - `data` (array[object]) 変数のリスト
  846. - `id` (string) 変数 ID
  847. - `name` (string) 変数名
  848. - `value_type` (string) 変数タイプ(文字列、数値、真偽値など)
  849. - `value` (string) 変数値
  850. - `description` (string) 変数の説明
  851. - `created_at` (int) 作成タイムスタンプ
  852. - `updated_at` (int) 最終更新タイムスタンプ
  853. ### エラー
  854. - 404, `conversation_not_exists`, 会話が見つかりません
  855. </Col>
  856. <Col sticky>
  857. <CodeGroup title="Request" tag="GET" label="/conversations/:conversation_id/variables" targetCode={`curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123' \\\n--header 'Authorization: Bearer {api_key}'`}>
  858. ```bash {{ title: 'cURL' }}
  859. curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123' \
  860. --header 'Authorization: Bearer {api_key}'
  861. ```
  862. </CodeGroup>
  863. <CodeGroup title="Request with variable name filter">
  864. ```bash {{ title: 'cURL' }}
  865. curl -X GET '${props.appDetail.api_base_url}/conversations/{conversation_id}/variables?user=abc-123&variable_name=customer_name' \
  866. --header 'Authorization: Bearer {api_key}'
  867. ```
  868. </CodeGroup>
  869. <CodeGroup title="Response">
  870. ```json {{ title: 'Response' }}
  871. {
  872. "limit": 100,
  873. "has_more": false,
  874. "data": [
  875. {
  876. "id": "variable-uuid-1",
  877. "name": "customer_name",
  878. "value_type": "string",
  879. "value": "John Doe",
  880. "description": "会話から抽出された顧客名",
  881. "created_at": 1650000000000,
  882. "updated_at": 1650000000000
  883. },
  884. {
  885. "id": "variable-uuid-2",
  886. "name": "order_details",
  887. "value_type": "json",
  888. "value": "{\"product\":\"Widget\",\"quantity\":5,\"price\":19.99}",
  889. "description": "顧客の注文詳細",
  890. "created_at": 1650000000000,
  891. "updated_at": 1650000000000
  892. }
  893. ]
  894. }
  895. ```
  896. </CodeGroup>
  897. </Col>
  898. </Row>
  899. ---
  900. <Heading
  901. url='/audio-to-text'
  902. method='POST'
  903. title='音声からテキストへ'
  904. name='#audio'
  905. />
  906. <Row>
  907. <Col>
  908. このエンドポイントは multipart/form-data リクエストを必要とします。
  909. ### リクエストボディ
  910. <Properties>
  911. <Property name='file' type='file' key='file'>
  912. オーディオファイル。
  913. サポートされている形式:`['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm']`
  914. ファイルサイズ制限:15MB
  915. </Property>
  916. <Property name='user' type='string' key='user'>
  917. ユーザー識別子、開発者のルールによって定義され、アプリケーション内で一意でなければなりません。
  918. </Property>
  919. </Properties>
  920. ### 応答
  921. - `text` (string) 出力テキスト
  922. </Col>
  923. <Col sticky>
  924. <CodeGroup title="リクエスト" tag="POST" label="/audio-to-text" targetCode={`curl -X POST '${props.appDetail.api_base_url}/audio-to-text' \\\n--header 'Authorization: Bearer {api_key}' \\\n--form 'file=@localfile;type=audio/[mp3|mp4|mpeg|mpga|m4a|wav|webm]'`}>
  925. ```bash {{ title: 'cURL' }}
  926. curl -X POST '${props.appDetail.api_base_url}/conversations/name' \
  927. --header 'Authorization: Bearer {api_key}' \
  928. --form 'file=@localfile;type=audio/mp3'
  929. ```
  930. </CodeGroup>
  931. <CodeGroup title="応答">
  932. ```json {{ title: '応答' }}
  933. {
  934. "text": ""
  935. }
  936. ```
  937. </CodeGroup>
  938. </Col>
  939. </Row>
  940. ---
  941. <Heading
  942. url='/text-to-audio'
  943. method='POST'
  944. title='テキストから音声へ'
  945. name='#audio'
  946. />
  947. <Row>
  948. <Col>
  949. テキストを音声に変換します。
  950. ### リクエストボディ
  951. <Properties>
  952. <Property name='message_id' type='str' key='message_id'>
  953. Difyによって生成されたテキストメッセージの場合、生成されたメッセージIDを直接渡します。バックエンドはメッセージIDを使用して対応する内容を検索し、音声情報を直接合成します。message_idとtextが同時に提供される場合、message_idが優先されます。
  954. </Property>
  955. <Property name='text' type='str' key='text'>
  956. 音声生成コンテンツ。
  957. </Property>
  958. <Property name='user' type='string' key='user'>
  959. ユーザー識別子、開発者によって定義され、アプリ内で一意であることを保証しなければなりません。
  960. </Property>
  961. </Properties>
  962. </Col>
  963. <Col sticky>
  964. <CodeGroup title="リクエスト" tag="POST" label="/text-to-audio" targetCode={`curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \\\n--header 'Authorization: Bearer {api_key}' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",\n "text": "Hello Dify",\n "user": "abc-123"\n}'`}>
  965. ```bash {{ title: 'cURL' }}
  966. curl -o text-to-audio.mp3 -X POST '${props.appDetail.api_base_url}/text-to-audio' \
  967. --header 'Authorization: Bearer {api_key}' \
  968. --header 'Content-Type: application/json' \
  969. --data-raw '{
  970. "message_id": "5ad4cb98-f0c7-4085-b384-88c403be6290",
  971. "text": "Hello Dify",
  972. "user": "abc-123",
  973. "streaming": false
  974. }'
  975. ```
  976. </CodeGroup>
  977. <CodeGroup title="ヘッダー">
  978. ```json {{ title: 'ヘッダー' }}
  979. {
  980. "Content-Type": "audio/wav"
  981. }
  982. ```
  983. </CodeGroup>
  984. </Col>
  985. </Row>
  986. ---
  987. <Heading
  988. url='/info'
  989. method='GET'
  990. title='アプリケーションの基本情報を取得'
  991. name='#info'
  992. />
  993. <Row>
  994. <Col>
  995. このアプリケーションの基本情報を取得するために使用されます
  996. ### Response
  997. - `name` (string) アプリケーションの名前
  998. - `description` (string) アプリケーションの説明
  999. - `tags` (array[string]) アプリケーションのタグ
  1000. - `mode` (string) アプリケーションのモード
  1001. - `author_name` (string) 作者の名前
  1002. </Col>
  1003. <Col>
  1004. <CodeGroup title="Request" tag="GET" label="/info" targetCode={`curl -X GET '${props.appDetail.api_base_url}/info' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1005. ```bash {{ title: 'cURL' }}
  1006. curl -X GET '${props.appDetail.api_base_url}/info' \
  1007. -H 'Authorization: Bearer {api_key}'
  1008. ```
  1009. </CodeGroup>
  1010. <CodeGroup title="Response">
  1011. ```json {{ title: 'Response' }}
  1012. {
  1013. "name": "My App",
  1014. "description": "This is my app.",
  1015. "tags": [
  1016. "tag1",
  1017. "tag2"
  1018. ],
  1019. "mode": "advanced-chat",
  1020. "author_name": "Dify"
  1021. }
  1022. ```
  1023. </CodeGroup>
  1024. </Col>
  1025. </Row>
  1026. ---
  1027. <Heading
  1028. url='/parameters'
  1029. method='GET'
  1030. title='アプリケーションのパラメータ情報を取得'
  1031. name='#parameters'
  1032. />
  1033. <Row>
  1034. <Col>
  1035. ページに入る際に、機能、入力パラメータ名、タイプ、デフォルト値などの情報を取得するために使用されます。
  1036. ### 応答
  1037. - `opening_statement` (string) 開始の挨拶
  1038. - `suggested_questions` (array[string]) 開始時の推奨質問のリスト
  1039. - `suggested_questions_after_answer` (object) 答えを有効にした後の質問を提案します。
  1040. - `enabled` (bool) 有効かどうか
  1041. - `speech_to_text` (object) 音声からテキストへ
  1042. - `enabled` (bool) 有効かどうか
  1043. - `text_to_speech` (object) テキストから音声へ
  1044. - `enabled` (bool) 有効かどうか
  1045. - `voice` (string) 音声タイプ
  1046. - `language` (string) 言語
  1047. - `autoPlay` (string) 自動再生
  1048. - `enabled` 有効
  1049. - `disabled` 無効
  1050. - `retriever_resource` (object) 引用と帰属
  1051. - `enabled` (bool) 有効かどうか
  1052. - `annotation_reply` (object) 注釈返信
  1053. - `enabled` (bool) 有効かどうか
  1054. - `user_input_form` (array[object]) ユーザー入力フォームの設定
  1055. - `text-input` (object) テキスト入力コントロール
  1056. - `label` (string) 変数表示ラベル名
  1057. - `variable` (string) 変数ID
  1058. - `required` (bool) 必須かどうか
  1059. - `default` (string) デフォルト値
  1060. - `paragraph` (object) 段落テキスト入力コントロール
  1061. - `label` (string) 変数表示ラベル名
  1062. - `variable` (string) 変数ID
  1063. - `required` (bool) 必須かどうか
  1064. - `default` (string) デフォルト値
  1065. - `select` (object) ドロップダウンコントロール
  1066. - `label` (string) 変数表示ラベル名
  1067. - `variable` (string) 変数ID
  1068. - `required` (bool) 必須かどうか
  1069. - `default` (string) デフォルト値
  1070. - `options` (array[string]) オプション値
  1071. - `file_upload` (object) ファイルアップロード設定
  1072. - `document` (object) ドキュメント設定
  1073. 現在サポートされているドキュメントタイプ:`txt`, `md`, `markdown`, `pdf`, `html`, `xlsx`, `xls`, `docx`, `csv`, `eml`, `msg`, `pptx`, `ppt`, `xml`, `epub`。
  1074. - `enabled` (bool) 有効かどうか
  1075. - `number_limits` (int) ドキュメント数の上限。デフォルトは 3
  1076. - `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
  1077. - `image` (object) 画像設定
  1078. 現在サポートされている画像タイプ:`png`, `jpg`, `jpeg`, `webp`, `gif`。
  1079. - `enabled` (bool) 有効かどうか
  1080. - `number_limits` (int) 画像数の上限。デフォルトは 3
  1081. - `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
  1082. - `audio` (object) オーディオ設定
  1083. 現在サポートされているオーディオタイプ:`mp3`, `m4a`, `wav`, `webm`, `amr`。
  1084. - `enabled` (bool) 有効かどうか
  1085. - `number_limits` (int) オーディオ数の上限。デフォルトは 3
  1086. - `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
  1087. - `video` (object) ビデオ設定
  1088. 現在サポートされているビデオタイプ:`mp4`, `mov`, `mpeg`, `mpga`。
  1089. - `enabled` (bool) 有効かどうか
  1090. - `number_limits` (int) ビデオ数の上限。デフォルトは 3
  1091. - `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
  1092. - `custom` (object) カスタム設定
  1093. - `enabled` (bool) 有効かどうか
  1094. - `number_limits` (int) カスタム数の上限。デフォルトは 3
  1095. - `transfer_methods` (array[string]) 転送方法リスト:`remote_url`, `local_file`。いずれかを選択する必要があります。
  1096. - `system_parameters` (object) システムパラメータ
  1097. - `file_size_limit` (int) ドキュメントアップロードサイズ制限(MB)
  1098. - `image_file_size_limit` (int) 画像ファイルアップロードサイズ制限(MB)
  1099. - `audio_file_size_limit` (int) オーディオファイルアップロードサイズ制限(MB)
  1100. - `video_file_size_limit` (int) ビデオファイルアップロードサイズ制限(MB)
  1101. </Col>
  1102. <Col sticky>
  1103. <CodeGroup title="リクエスト" tag="GET" label="/parameters" targetCode={` curl -X GET '${props.appDetail.api_base_url}/parameters'`}>
  1104. ```bash {{ title: 'cURL' }}
  1105. curl -X GET '${props.appDetail.api_base_url}/parameters' \
  1106. --header 'Authorization: Bearer {api_key}'
  1107. ```
  1108. </CodeGroup>
  1109. <CodeGroup title="応答">
  1110. ```json {{ title: '応答' }}
  1111. {
  1112. "opening_statement": "こんにちは!",
  1113. "suggested_questions_after_answer": {
  1114. "enabled": true
  1115. },
  1116. "speech_to_text": {
  1117. "enabled": true
  1118. },
  1119. "text_to_speech": {
  1120. "enabled": true,
  1121. "voice": "sambert-zhinan-v1",
  1122. "language": "zh-Hans",
  1123. "autoPlay": "disabled"
  1124. },
  1125. "retriever_resource": {
  1126. "enabled": true
  1127. },
  1128. "annotation_reply": {
  1129. "enabled": true
  1130. },
  1131. "user_input_form": [
  1132. {
  1133. "paragraph": {
  1134. "label": "クエリ",
  1135. "variable": "query",
  1136. "required": true,
  1137. "default": ""
  1138. }
  1139. }
  1140. ],
  1141. "file_upload": {
  1142. "image": {
  1143. "enabled": false,
  1144. "number_limits": 3,
  1145. "detail": "high",
  1146. "transfer_methods": [
  1147. "remote_url",
  1148. "local_file"
  1149. ]
  1150. }
  1151. },
  1152. "system_parameters": {
  1153. "file_size_limit": 15,
  1154. "image_file_size_limit": 10,
  1155. "audio_file_size_limit": 50,
  1156. "video_file_size_limit": 100
  1157. }
  1158. }
  1159. ```
  1160. </CodeGroup>
  1161. </Col>
  1162. </Row>
  1163. ---
  1164. <Heading
  1165. url='/meta'
  1166. method='GET'
  1167. title='アプリケーションのメタ情報を取得'
  1168. name='#meta'
  1169. />
  1170. <Row>
  1171. <Col>
  1172. このアプリケーションのツールのアイコンを取得するために使用されます
  1173. ### 応答
  1174. - `tool_icons`(object[string]) ツールアイコン
  1175. - `tool_name` (string)
  1176. - `icon` (object|string)
  1177. - (object) アイコンオブジェクト
  1178. - `background` (string) 背景色(16 進数形式)
  1179. - `content`(string) 絵文字
  1180. - (string) アイコンの URL
  1181. </Col>
  1182. <Col>
  1183. <CodeGroup title="リクエスト" tag="GET" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/meta' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1184. ```bash {{ title: 'cURL' }}
  1185. curl -X GET '${props.appDetail.api_base_url}/meta' \
  1186. -H 'Authorization: Bearer {api_key}'
  1187. ```
  1188. </CodeGroup>
  1189. <CodeGroup title="応答">
  1190. ```json {{ title: '応答' }}
  1191. {
  1192. "tool_icons": {
  1193. "dalle2": "https://cloud.dify.ai/console/api/workspaces/current/tool-provider/builtin/dalle/icon",
  1194. "api_tool": {
  1195. "background": "#252525",
  1196. "content": "\ud83d\ude01"
  1197. }
  1198. }
  1199. }
  1200. ```
  1201. </CodeGroup>
  1202. </Col>
  1203. </Row>
  1204. ---
  1205. <Heading
  1206. url='/site'
  1207. method='GET'
  1208. title='アプリのWebApp設定を取得'
  1209. name='#site'
  1210. />
  1211. <Row>
  1212. <Col>
  1213. アプリの WebApp 設定を取得するために使用します。
  1214. ### 応答
  1215. - `title` (string) WebApp 名
  1216. - `chat_color_theme` (string) チャットの色テーマ、16 進数形式
  1217. - `chat_color_theme_inverted` (bool) チャットの色テーマを反転するかどうか
  1218. - `icon_type` (string) アイコンタイプ、`emoji`-絵文字、`image`-画像
  1219. - `icon` (string) アイコン。`emoji`タイプの場合は絵文字、`image`タイプの場合は画像 URL
  1220. - `icon_background` (string) 16 進数形式の背景色
  1221. - `icon_url` (string) アイコンの URL
  1222. - `description` (string) 説明
  1223. - `copyright` (string) 著作権情報
  1224. - `privacy_policy` (string) プライバシーポリシーのリンク
  1225. - `custom_disclaimer` (string) カスタム免責事項
  1226. - `default_language` (string) デフォルト言語
  1227. - `show_workflow_steps` (bool) ワークフローの詳細を表示するかどうか
  1228. - `use_icon_as_answer_icon` (bool) WebApp のアイコンをチャット内の🤖に置き換えるかどうか
  1229. </Col>
  1230. <Col>
  1231. <CodeGroup title="Request" tag="POST" label="/meta" targetCode={`curl -X GET '${props.appDetail.api_base_url}/site' \\\n-H 'Authorization: Bearer {api_key}'`}>
  1232. ```bash {{ title: 'cURL' }}
  1233. curl -X GET '${props.appDetail.api_base_url}/site' \
  1234. -H 'Authorization: Bearer {api_key}'
  1235. ```
  1236. </CodeGroup>
  1237. <CodeGroup title="Response">
  1238. ```json {{ title: 'Response' }}
  1239. {
  1240. "title": "My App",
  1241. "chat_color_theme": "#ff4a4a",
  1242. "chat_color_theme_inverted": false,
  1243. "icon_type": "emoji",
  1244. "icon": "😄",
  1245. "icon_background": "#FFEAD5",
  1246. "icon_url": null,
  1247. "description": "This is my app.",
  1248. "copyright": "all rights reserved",
  1249. "privacy_policy": "",
  1250. "custom_disclaimer": "All generated by AI",
  1251. "default_language": "en-US",
  1252. "show_workflow_steps": false,
  1253. "use_icon_as_answer_icon": false,
  1254. }
  1255. ```
  1256. </CodeGroup>
  1257. </Col>
  1258. </Row>
  1259. ___