@@ -34,17 +34,13 @@ weight: 852
3434
3535### 请求
3636
37- <!-- #### v2
38-
39- v1,v2 接口请求参数一致,仅请求地址不一样。
40-
4137{{< tabs tabTotal="3" >}}
4238{{< tab tabName="基础请求示例" >}}
4339{{< markdownify >}}
4440
4541``` bash
46- curl --location --request POST 'http://localhost:3000/api/v2 /chat/completions' \
47- --header 'Authorization: fastgpt-xxxxxx' \
42+ curl --location --request POST ' http://localhost:3000/api/v1 /chat/completions' \
43+ --header ' Authorization: Bearer fastgpt-xxxxxx' \
4844--header ' Content-Type: application/json' \
4945--data-raw ' {
5046 "chatId": "my_chatId",
@@ -58,7 +54,7 @@ curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
5854 "messages": [
5955 {
6056 "role": "user",
61- "content": "你是谁 "
57+ "content": "导演是谁 "
6258 }
6359 ]
6460}'
@@ -74,7 +70,7 @@ curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
7470* 目前不支持上传文件,需上传到自己的对象存储中,获取对应的文件链接。
7571
7672``` bash
77- curl --location --request POST 'http://localhost:3000/api/v2 /chat/completions' \
73+ curl --location --request POST ' http://localhost:3000/api/v1 /chat/completions' \
7874--header ' Authorization: Bearer fastgpt-xxxxxx' \
7975--header ' Content-Type: application/json' \
8076--data-raw ' {
@@ -126,15 +122,17 @@ curl --location --request POST 'http://localhost:3000/api/v2/chat/completions' \
126122{{< /tab >}}
127123{{< /tabs >}}
128124
129- #### v1
125+ <!-- #### v2
126+
127+ v1,v2 接口请求参数一致,仅请求地址不一样。
130128
131129{{< tabs tabTotal="3" >}}
132130{{< tab tabName="基础请求示例" >}}
133131{{< markdownify >}}
134132
135133```bash
136- curl --location --request POST 'http://localhost:3000/api/v1 /chat/completions' \
137- --header 'Authorization: Bearer fastgpt-xxxxxx' \
134+ curl --location --request POST 'http://localhost:3000/api/v2 /chat/completions' \
135+ --header 'Authorization: fastgpt-xxxxxx' \
138136--header 'Content-Type: application/json' \
139137--data-raw '{
140138 "chatId": "my_chatId",
@@ -148,7 +146,7 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
148146 "messages": [
149147 {
150148 "role": "user",
151- "content": "导演是谁 "
149+ "content": "你是谁 "
152150 }
153151 ]
154152}'
@@ -164,7 +162,7 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
164162* 目前不支持上传文件,需上传到自己的对象存储中,获取对应的文件链接。
165163
166164```bash
167- curl --location --request POST 'http://localhost:3000/api/v1 /chat/completions' \
165+ curl --location --request POST 'http://localhost:3000/api/v2 /chat/completions' \
168166--header 'Authorization: Bearer fastgpt-xxxxxx' \
169167--header 'Content-Type: application/json' \
170168--data-raw '{
@@ -216,6 +214,10 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
216214{{< /tab >}}
217215{{< /tabs >}}
218216
217+ #### v1
218+
219+
220+
219221### 响应
220222
221223#### v2
@@ -745,8 +747,6 @@ curl --location --request POST 'https://api.fastgpt.in/api/v1/chat/completions'
745747
746748### 请求示例
747749
748- #### v1
749-
750750``` bash
751751curl --location --request POST ' http://localhost:3000/api/v1/chat/completions' \
752752--header ' Authorization: Bearer test-xxxxx' \
@@ -760,25 +760,8 @@ curl --location --request POST 'http://localhost:3000/api/v1/chat/completions' \
760760}'
761761```
762762
763- #### v2
764-
765- ``` bash
766- curl --location --request POST ' http://localhost:3000/api/v2/chat/completions' \
767- --header ' Authorization: Bearer test-xxxxx' \
768- --header ' Content-Type: application/json' \
769- --data-raw ' {
770- "stream": false,
771- "chatId": "test",
772- "variables": {
773- "query":"你好"
774- }
775- }'
776- ```
777-
778763### 响应示例
779764
780- #### v1
781-
782765{{< tabs tabTotal="3" >}}
783766
784767{{< tab tabName="detail=true,stream=false 响应" >}}
@@ -937,151 +920,6 @@ event取值:
937920{{< /tab >}}
938921{{< /tabs >}}
939922
940-
941- #### v2
942-
943- {{< tabs tabTotal="3" >}}
944-
945- {{< tab tabName="detail=true,stream=false 响应" >}}
946- {{< markdownify >}}
947-
948- * 插件的输出可以通过查找` responseData ` 中, ` moduleType=pluginOutput ` 的元素,其` pluginOutput ` 是插件的输出。
949- * 流输出,仍可以通过` choices ` 进行获取。
950-
951- ``` json
952- {
953- "responseData" : [
954- {
955- "id" : " bsH1ZdbYkz9iJwYa" ,
956- "nodeId" : " pluginInput" ,
957- "moduleName" : " workflow:template.plugin_start" ,
958- "moduleType" : " pluginInput" ,
959- "runningTime" : 0
960- },
961- {
962- "id" : " zDgfqSPhbYZFHVIn" ,
963- "nodeId" : " h4Gr4lJtFVQ6qI4c" ,
964- "moduleName" : " AI 对话" ,
965- "moduleType" : " chatNode" ,
966- "runningTime" : 1.44 ,
967- "totalPoints" : 0 ,
968- "model" : " GPT-4o-mini" ,
969- "tokens" : 34 ,
970- "inputTokens" : 8 ,
971- "outputTokens" : 26 ,
972- "query" : " 你好" ,
973- "reasoningText" : " " ,
974- "historyPreview" : [
975- {
976- "obj" : " Human" ,
977- "value" : " 你好"
978- },
979- {
980- "obj" : " AI" ,
981- "value" : " 你好!有什么我可以帮助你的吗?"
982- }
983- ],
984- "contextTotalLen" : 2
985- },
986- {
987- "id" : " uLLwKKRZvufXzgF4" ,
988- "nodeId" : " pluginOutput" ,
989- "moduleName" : " common:core.module.template.self_output" ,
990- "moduleType" : " pluginOutput" ,
991- "runningTime" : 0 ,
992- "totalPoints" : 0 ,
993- "pluginOutput" : {
994- "result" : " 你好!有什么我可以帮助你的吗?"
995- }
996- }
997- ],
998- "newVariables" : {
999-
1000- },
1001- "id" : " test" ,
1002- "model" : " " ,
1003- "usage" : {
1004- "prompt_tokens" : 1 ,
1005- "completion_tokens" : 1 ,
1006- "total_tokens" : 1
1007- },
1008- "choices" : [
1009- {
1010- "message" : {
1011- "role" : " assistant" ,
1012- "content" : " 你好!有什么我可以帮助你的吗?"
1013- },
1014- "finish_reason" : " stop" ,
1015- "index" : 0
1016- }
1017- ]
1018- }
1019- ```
1020-
1021- {{< /markdownify >}}
1022- {{< /tab >}}
1023-
1024-
1025- {{< tab tabName="detail=true,stream=true 响应" >}}
1026- {{< markdownify >}}
1027-
1028- * 插件的输出可以通过获取` event=flowResponses ` 中的字符串,并将其反序列化后得到一个数组。同样的,查找 ` moduleType=pluginOutput ` 的元素,其` pluginOutput ` 是插件的输出。
1029- * 流输出,仍和对话接口一样获取。
1030-
1031- ``` bash
1032- data: {" event" :" flowNodeResponse" ," data" :" {\" id\" :\" q8ablUOqHGgqLIRM\" ,\" nodeId\" :\" pluginInput\" ,\" moduleName\" :\" workflow:template.plugin_start\" ,\" moduleType\" :\" pluginInput\" ,\" runningTime\" :0}" }
1033-
1034- data: {" event" :" flowNodeStatus" ," data" :" {\" status\" :\" running\" ,\" name\" :\" AI 对话\" }" }
1035-
1036- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 你好\" },\" index\" :0,\" finish_reason\" :null}]}" }
1037-
1038- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" !\" },\" index\" :0,\" finish_reason\" :null}]}" }
1039-
1040- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 有什么\" },\" index\" :0,\" finish_reason\" :null}]}" }
1041-
1042- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 我\" },\" index\" :0,\" finish_reason\" :null}]}" }
1043-
1044- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 可以\" },\" index\" :0,\" finish_reason\" :null}]}" }
1045-
1046- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 帮助\" },\" index\" :0,\" finish_reason\" :null}]}" }
1047-
1048- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 你\" },\" index\" :0,\" finish_reason\" :null}]}" }
1049-
1050- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" 的吗\" },\" index\" :0,\" finish_reason\" :null}]}" }
1051-
1052- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" ?\" },\" index\" :0,\" finish_reason\" :null}]}" }
1053-
1054- data: {" event" :" flowNodeResponse" ," data" :" {\" id\" :\" rqlXLUap8QeiN7Kf\" ,\" nodeId\" :\" h4Gr4lJtFVQ6qI4c\" ,\" moduleName\" :\" AI 对话\" ,\" moduleType\" :\" chatNode\" ,\" runningTime\" :1.79,\" totalPoints\" :0,\" model\" :\" GPT-4o-mini\" ,\" tokens\" :137,\" inputTokens\" :111,\" outputTokens\" :26,\" query\" :\" 你好\" ,\" reasoningText\" :\"\" ,\" historyPreview\" :[{\" obj\" :\" Human\" ,\" value\" :\" [{\\\" renderTypeList\\\" :[\\\" reference\\\" ],\\\" selectedTypeInde\\ n\\ n...[hide 174 chars]...\\ n\\ ncanSelectImg\\\" :true,\\\" required\\\" :false,\\\" value\\\" :\\\" 你好\\\" }]\" },{\" obj\" :\" AI\" ,\" value\" :\" 你好!有什么我可以帮助你的吗?\" },{\" obj\" :\" Human\" ,\" value\" :\" 你好\" },{\" obj\" :\" AI\" ,\" value\" :\" 你好!有什么我可以帮助你的吗?\" }],\" contextTotalLen\" :4}" }
1055-
1056- data: {" event" :" flowNodeResponse" ," data" :" {\" id\" :\" lHCpHI0MrM00HQlX\" ,\" nodeId\" :\" pluginOutput\" ,\" moduleName\" :\" common:core.module.template.self_output\" ,\" moduleType\" :\" pluginOutput\" ,\" runningTime\" :0,\" totalPoints\" :0,\" pluginOutput\" :{\" result\" :\" 你好!有什么我可以帮助你的吗?\" }}" }
1057-
1058- data: {" event" :" answer" ," data" :" {\" id\" :\"\" ,\" object\" :\"\" ,\" created\" :0,\" model\" :\"\" ,\" choices\" :[{\" delta\" :{\" role\" :\" assistant\" ,\" content\" :null},\" index\" :0,\" finish_reason\" :\" stop\" }]}" }
1059-
1060- data: {" event" :" answer" ," data" :" [DONE]" }
1061- ```
1062-
1063- {{< /markdownify >}}
1064- {{< /tab >}}
1065-
1066- {{< tab tabName="输出获取" >}}
1067- {{< markdownify >}}
1068-
1069- event取值:
1070-
1071- - answer: 返回给客户端的文本(最终会算作回答)
1072- - fastAnswer: 指定回复返回给客户端的文本(最终会算作回答)
1073- - toolCall: 执行工具
1074- - toolParams: 工具参数
1075- - toolResponse: 工具返回
1076- - flowNodeStatus: 运行到的节点状态
1077- - flowNodeResponse: 单个节点详细响应
1078- - updateVariables: 更新变量
1079- - error: 报错
1080-
1081- {{< /markdownify >}}
1082- {{< /tab >}}
1083- {{< /tabs >}}
1084-
1085923# 对话 CRUD
1086924
1087925{{% alert icon="🤖 " context="success" %}}
0 commit comments