Add python code snippet for developing with apis (#95)
* Add python code snippet for developing with apis * Update developing-with-apis.md * Add python code snippet to EN develop with apispull/97/head
parent
43f0333012
commit
a0479e33a7
|
|
@ -33,6 +33,8 @@ You can find the API documentation and example requests for this application in
|
|||
|
||||
For example, here is a sample call an API for text generation:
|
||||
|
||||
{% tabs %}
|
||||
{% tab title="cURL" %}
|
||||
```
|
||||
curl --location --request POST 'https://api.dify.ai/v1/completion-messages' \
|
||||
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
|
||||
|
|
@ -43,6 +45,32 @@ curl --location --request POST 'https://api.dify.ai/v1/completion-messages' \
|
|||
"user": "abc-123"
|
||||
}'
|
||||
```
|
||||
{% endtab %}
|
||||
|
||||
{% tab title="Python" %}
|
||||
```python
|
||||
import requests
|
||||
import json
|
||||
|
||||
url = "https://api.dify.ai/v1/completion-messages"
|
||||
|
||||
headers = {
|
||||
'Authorization': 'Bearer ENTER-YOUR-SECRET-KEY',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
data = {
|
||||
"inputs": {"text": 'Hello, how are you?'},
|
||||
"response_mode": "streaming",
|
||||
"user": "abc-123"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
|
||||
print(response.text)
|
||||
```
|
||||
{% endtab %}
|
||||
{% endtabs %}
|
||||
|
||||
### Conversational applications
|
||||
|
||||
|
|
@ -52,6 +80,8 @@ You can find the API documentation and example requests for this application in
|
|||
|
||||
For example, here is a sample call an API for chat-messages:
|
||||
|
||||
{% tabs %}
|
||||
{% tab title="cURL" %}
|
||||
```
|
||||
curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
|
||||
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
|
||||
|
|
@ -63,4 +93,31 @@ curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
|
|||
"conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276"
|
||||
"user": "abc-123"
|
||||
}'
|
||||
|
||||
```
|
||||
{% endtab %}
|
||||
|
||||
{% tab title="Python" %}
|
||||
```python
|
||||
import requests
|
||||
import json
|
||||
|
||||
url = 'https://api.dify.ai/v1/chat-messages'
|
||||
headers = {
|
||||
'Authorization': 'Bearer ENTER-YOUR-SECRET-KEY',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
data = {
|
||||
"inputs": {},
|
||||
"query": "eh",
|
||||
"response_mode": "streaming",
|
||||
"conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
|
||||
"user": "abc-123"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
|
||||
print(response.json())
|
||||
```
|
||||
{% endtab %}
|
||||
{% endtabs %}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ Dify 基于“**后端即服务**”理念为所有应用提供了 API,为 AI
|
|||
你可以在**应用 -> 访问 API** 中找到该应用的 API 文档与范例请求。
|
||||
|
||||
例如,创建文本补全信息的 API 的调用示例:
|
||||
|
||||
{% tabs %}
|
||||
{% tab title="cURL" %}
|
||||
```
|
||||
curl --location --request POST 'https://api.dify.ai/v1/completion-messages' \
|
||||
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
|
||||
|
|
@ -42,8 +43,34 @@ curl --location --request POST 'https://api.dify.ai/v1/completion-messages' \
|
|||
"response_mode": "streaming",
|
||||
"user": "abc-123"
|
||||
}'
|
||||
|
||||
```
|
||||
{% endtab %}
|
||||
|
||||
{% tab title="Python" %}
|
||||
```python
|
||||
import requests
|
||||
import json
|
||||
|
||||
url = "https://api.dify.ai/v1/completion-messages"
|
||||
|
||||
headers = {
|
||||
'Authorization': 'Bearer ENTER-YOUR-SECRET-KEY',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
data = {
|
||||
"inputs": {"text": 'Hello, how are you?'},
|
||||
"response_mode": "streaming",
|
||||
"user": "abc-123"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
|
||||
print(response.text)
|
||||
```
|
||||
{% endtab %}
|
||||
{% endtabs %}
|
||||
|
||||
|
||||
### 对话型应用
|
||||
|
||||
|
|
@ -52,7 +79,8 @@ curl --location --request POST 'https://api.dify.ai/v1/completion-messages' \
|
|||
你可以在**应用 -> 访问 API** 中找到该应用的 API 文档与范例请求。
|
||||
|
||||
例如,发送对话信息的 API的调用示例:
|
||||
|
||||
{% tabs %}
|
||||
{% tab title="cURL" %}
|
||||
```
|
||||
curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
|
||||
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
|
||||
|
|
@ -66,3 +94,29 @@ curl --location --request POST 'https://api.dify.ai/v1/chat-messages' \
|
|||
}'
|
||||
|
||||
```
|
||||
{% endtab %}
|
||||
|
||||
{% tab title="Python" %}
|
||||
```python
|
||||
import requests
|
||||
import json
|
||||
|
||||
url = 'https://api.dify.ai/v1/chat-messages'
|
||||
headers = {
|
||||
'Authorization': 'Bearer ENTER-YOUR-SECRET-KEY',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
data = {
|
||||
"inputs": {},
|
||||
"query": "eh",
|
||||
"response_mode": "streaming",
|
||||
"conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
|
||||
"user": "abc-123"
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
||||
|
||||
print(response.json())
|
||||
```
|
||||
{% endtab %}
|
||||
{% endtabs %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue