|
| 1 | +# Maintain Annotations via API |
| 2 | + |
| 3 | +> Authentication and invocation methods are consistent with the App Service API. |
| 4 | +
|
| 5 | +Maintaining annotations via API allows for operations such as adding, deleting, updating, and querying annotations. This provides more comprehensive third-party system integration capabilities. |
| 6 | + |
| 7 | +## How to Use |
| 8 | + |
| 9 | +Enter the workspace, go to the application, and click on Access API on the left side. Click on API Key in the upper right corner, then click Create Key. This will give you a key specific to this application. The API interface will recognize the application based on this key. |
| 10 | + |
| 11 | +## API Call Examples |
| 12 | + |
| 13 | +### Get Annotation List |
| 14 | + |
| 15 | +```bash |
| 16 | +curl --location --request GET 'https://api.dify.ai/v1/apps/annotations?page=1&limit=20' \ |
| 17 | +--header 'Authorization: Bearer {api_key}' |
| 18 | +``` |
| 19 | + |
| 20 | +Output Example: |
| 21 | + |
| 22 | +```json |
| 23 | +{ |
| 24 | + "data": [ |
| 25 | + { |
| 26 | + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", |
| 27 | + "question": "What is your name?", |
| 28 | + "answer": "I am Dify.", |
| 29 | + "hit_count": 0, |
| 30 | + "created_at": 1735625869 |
| 31 | + } |
| 32 | + ], |
| 33 | + "has_more": false, |
| 34 | + "limit": 20, |
| 35 | + "total": 1, |
| 36 | + "page": 1 |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +### Create Annotation |
| 41 | + |
| 42 | +```bash |
| 43 | +curl --location --request POST 'https://api.dify.ai/v1/apps/annotations' \ |
| 44 | +--header 'Authorization: Bearer {api_key}' \ |
| 45 | +--header 'Content-Type: application/json' \ |
| 46 | +--data-raw '{ |
| 47 | + "question": "What is your name?", |
| 48 | + "answer": "I am Dify." |
| 49 | +}' |
| 50 | +``` |
| 51 | + |
| 52 | +Output Example: |
| 53 | + |
| 54 | +```json |
| 55 | +{ |
| 56 | + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", |
| 57 | + "question": "What is your name?", |
| 58 | + "answer": "I am Dify.", |
| 59 | + "hit_count": 0, |
| 60 | + "created_at": 1735625869 |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Update Annotation |
| 65 | + |
| 66 | +```bash |
| 67 | +curl --location --request PUT 'https://api.dify.ai/v1/apps/annotations/{annotation_id}' \ |
| 68 | +--header 'Authorization: Bearer {api_key}' \ |
| 69 | +--header 'Content-Type: application/json' \ |
| 70 | +--data-raw '{ |
| 71 | + "question": "What is your name?", |
| 72 | + "answer": "I am Dify." |
| 73 | +}' |
| 74 | +``` |
| 75 | + |
| 76 | +Output Example: |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "id": "69d48372-ad81-4c75-9c46-2ce197b4d402", |
| 81 | + "question": "What is your name?", |
| 82 | + "answer": "I am Dify.", |
| 83 | + "hit_count": 0, |
| 84 | + "created_at": 1735625869 |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +### Delete Annotation |
| 89 | + |
| 90 | +```bash |
| 91 | +curl --location --request DELETE 'https://api.dify.ai/v1/apps/annotations/{annotation_id}' \ |
| 92 | +--header 'Authorization: Bearer {api_key}' |
| 93 | +``` |
| 94 | + |
| 95 | +Output Example: |
| 96 | + |
| 97 | +```json |
| 98 | +{"result": "success"} |
| 99 | +``` |
| 100 | + |
| 101 | +### Initial Annotation Reply Settings |
| 102 | + |
| 103 | +```bash |
| 104 | +curl --location --request POST 'https://api.dify.ai/v1/apps/annotation-reply/{action}' \ |
| 105 | +--header 'Authorization: Bearer {api_key}' \ |
| 106 | +--header 'Content-Type: application/json' \ |
| 107 | +--data-raw '{ |
| 108 | + "score_threshold": 0.9, |
| 109 | + "embedding_provider_name": "zhipu", |
| 110 | + "embedding_model_name": "embedding_3" |
| 111 | +}' |
| 112 | +``` |
| 113 | + |
| 114 | +Parameter Description: |
| 115 | +- `action`: Can only be `enable` or `disable` |
| 116 | +- `embedding_model_provider`: Specified embedding model provider, must be set up in the system first, corresponding to the provider field |
| 117 | +- `embedding_model`: Specified embedding model, corresponding to the model field |
| 118 | +- `retrieval_model`: Specified retrieval model, corresponding to the model field |
| 119 | + |
| 120 | +The provider and model name of the embedding model can be obtained through the following interface: `v1/workspaces/current/models/model-types/text-embedding`. For specific instructions, see: [Maintain Knowledge Base via API](guides/knowledge-base/maintain-dataset-via-api.md). The Authorization used is the Dataset API Token. |
| 121 | + |
| 122 | +Output Example: |
| 123 | + |
| 124 | +```json |
| 125 | +{ |
| 126 | + "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802", |
| 127 | + "job_status": "waiting" |
| 128 | +} |
| 129 | +``` |
| 130 | +This interface is executed asynchronously, so it will return a job_id. You can get the final execution result by querying the job status interface. |
| 131 | + |
| 132 | +### Query Initial Annotation Reply Settings Task Status |
| 133 | + |
| 134 | +```bash |
| 135 | +curl --location --request GET 'https://api.dify.ai/v1/apps/annotation-reply/{action}/status/{job_id}' \ |
| 136 | +--header 'Authorization: Bearer {api_key}' |
| 137 | +``` |
| 138 | + |
| 139 | +Output Example: |
| 140 | + |
| 141 | +```json |
| 142 | +{ |
| 143 | + "job_id": "b15c8f68-1cf4-4877-bf21-ed7cf2011802", |
| 144 | + "job_status": "waiting", |
| 145 | + "error_msg": "" |
| 146 | +} |
| 147 | +``` |
0 commit comments