template.en.mdx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { CodeGroup } from '../code.tsx'
  2. import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from '../md.tsx'
  3. # Completion App API
  4. For high-quality text generation, such as articles, summaries, and translations, use the completion-messages API with user input. Text generation relies on the model parameters and prompt templates set in Dify Prompt Engineering.
  5. <Heading
  6. url='/completion-messages'
  7. method='POST'
  8. title='Create Completion Message'
  9. name='#Create-Completion-Message'
  10. />
  11. <Row>
  12. <Col>
  13. Create a Completion Message to support the question-and-answer mode.
  14. ### Request Body
  15. <Properties>
  16. <Property name='inputs' type='object' key='inputs'>
  17. (Optional) Provide user input fields as key-value pairs, corresponding to variables in Prompt Eng. Key is the variable name, Value is the parameter value. If the field type is Select, the submitted Value must be one of the preset choices.
  18. <ul>
  19. {!!props.variables.length && props.variables.map(
  20. val => (
  21. <SubProperty name={val.key} type={val.type} key={val.key}>
  22. {val.name ? `${val.name}` : ''}
  23. </SubProperty>
  24. )
  25. )}
  26. </ul>
  27. </Property>
  28. <Property name='response_mode' type='string' key='response_mode'>
  29. - Blocking type, waiting for execution to complete and returning results. (Requests may be interrupted if the process is long)
  30. - streaming returns. Implementation of streaming return based on SSE (**[Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)**).
  31. </Property>
  32. <Property name='user' type='string' key='user'>
  33. The user identifier, defined by the developer, must ensure uniqueness within the app.
  34. </Property>
  35. </Properties>
  36. </Col>
  37. <Col sticky>
  38. <CodeGroup title="Request" tag="POST" label="/completion-messages" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/completion-messages' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n "inputs": ${JSON.stringify(props.inputs)},\n "response_mode": "streaming"\n "user": "abc-123"\n}'\n`}>
  39. ```bash {{ title: 'cURL' }}
  40. curl --location --request POST 'https://cloud.langgenius.dev/api/completion-messages' \
  41. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  42. --header 'Content-Type: application/json' \
  43. --data-raw '{
  44. "inputs": {},
  45. "response_mode": "streaming",
  46. "user": "abc-123"
  47. }'
  48. ```
  49. </CodeGroup>
  50. ### blocking
  51. <CodeGroup title="Response">
  52. ```json {{ title: 'Response' }}
  53. {
  54. "id": "0b089b9a-24d9-48cc-94f8-762677276261",
  55. "answer": "how are you?",
  56. "created_at": 1679586667
  57. }
  58. ```
  59. </CodeGroup>
  60. ### streaming
  61. <CodeGroup title="Response">
  62. ```streaming {{ title: 'Response' }}
  63. data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
  64. data: {"id": "5ad4cb98-f0c7-4085-b384-88c403be6290", "answer": " I", "created_at": 1679586595}
  65. ```
  66. </CodeGroup>
  67. </Col>
  68. </Row>
  69. ---
  70. <Heading
  71. url='/messages/{message_id}/feedbacks'
  72. method='POST'
  73. title='Message feedback (like)'
  74. name='#feedbacks'
  75. />
  76. <Row>
  77. <Col>
  78. Rate received messages on behalf of end-users with likes or dislikes. This data is visible in the Logs & Annotations page and used for future model fine-tuning.
  79. ### Path Params
  80. <Properties>
  81. <Property name='message_id' type='string' key='message_id'>
  82. Message ID
  83. </Property>
  84. </Properties>
  85. ### Request Body
  86. <Properties>
  87. <Property name='rating' type='string' key='rating'>
  88. like or dislike, null is undo
  89. </Property>
  90. <Property name='user' type='string' key='user'>
  91. The user identifier, defined by the developer, must ensure uniqueness within the app.
  92. </Property>
  93. </Properties>
  94. </Col>
  95. <Col sticky>
  96. <CodeGroup title="Request" tag="POST" label="/messages/{message_id}/feedbacks" targetCode={`curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json' \\\n --data-raw '{ \n "rating": "like",\n "user": "abc-123"\n}'`}>
  97. ```bash {{ title: 'cURL' }}
  98. curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \
  99. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
  100. --header 'Content-Type: application/json' \
  101. --data-raw '{
  102. "rating": "like",
  103. "user": "abc-123"
  104. }'
  105. ```
  106. </CodeGroup>
  107. <CodeGroup title="Response">
  108. ```json {{ title: 'Response' }}
  109. {
  110. "has_more": false,
  111. "data": [
  112. {
  113. "id": "WAz8eIbvDR60rouK",
  114. "username": "FrankMcCallister",
  115. "phone_number": "1-800-759-3000",
  116. "avatar_url": "https://assets.protocol.chat/avatars/frank.jpg",
  117. "display_name": null,
  118. "conversation_id": "xgQQXg3hrtjh7AvZ",
  119. "created_at": 692233200
  120. },
  121. {
  122. "id": "hSIhXBhNe8X1d8Et"
  123. // ...
  124. }
  125. ]
  126. }
  127. ```
  128. </CodeGroup>
  129. </Col>
  130. </Row>
  131. ---
  132. <Heading
  133. url='/parameters'
  134. method='GET'
  135. title='Obtain application parameter information'
  136. name='#parameters'
  137. />
  138. <Row>
  139. <Col>
  140. Retrieve configured Input parameters, including variable names, field names, types, and default values. Typically used for displaying these fields in a form or filling in default values after the client loads.
  141. ### Query
  142. <Properties>
  143. <Property name='user' type='string' key='user'>
  144. The user identifier, defined by the developer, must ensure uniqueness within the app.
  145. </Property>
  146. </Properties>
  147. </Col>
  148. <Col sticky>
  149. <CodeGroup title="Request" tag="GET" label="/parameters" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'`}>
  150. ```bash {{ title: 'cURL' }}
  151. curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \
  152. --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY'
  153. ```
  154. </CodeGroup>
  155. <CodeGroup title="Response">
  156. ```json {{ title: 'Response' }}
  157. {
  158. "introduction": "nice to meet you",
  159. "variables": [
  160. {
  161. "key": "book",
  162. "name": "Which book?",
  163. "description": null,
  164. "type": "string",
  165. "default": null,
  166. "options": null
  167. },
  168. {
  169. // ...
  170. ]
  171. }
  172. ```
  173. </CodeGroup>
  174. </Col>
  175. </Row>