You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/ai-gateway/evaluations/add-human-feedback-api.mdx
+31-70Lines changed: 31 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ sidebar:
5
5
order: 4
6
6
---
7
7
8
+
import { APIRequest } from"~/components";
9
+
8
10
This guide will walk you through the steps of adding human feedback to an AI Gateway request using the Cloudflare API. You will learn how to retrieve the relevant request logs, and submit feedback using the API.
9
11
10
12
If you prefer to add human feedback via the dashboard, refer to [Add Human Feedback](/ai-gateway/evaluations/add-human-feedback/).
@@ -19,21 +21,7 @@ If you prefer to add human feedback via the dashboard, refer to [Add Human Feedb
19
21
2. Get your [Account ID](/fundamentals/account/find-account-and-zone-ids/).
20
22
3. Using that API token and Account ID, send a [`POST` request](/api/resources/ai_gateway/methods/create/) to the Cloudflare API.
21
23
22
-
## 2. Using the API Token
23
-
24
-
Once you have the token, you can use it in API requests by adding it to the authorization header as a bearer token. Here is an example of how to use it in a request:
- Replace `{account_id}` and `{gateway_id}` with your specific Cloudflare account and gateway details.
34
-
- Replace `{your_api_token}` with the API token you just created.
35
-
36
-
## 3. Retrieve the `cf-aig-log-id`
24
+
## 2. Retrieve the `cf-aig-log-id`
37
25
38
26
The `cf-aig-log-id` is a unique identifier for the specific log entry to which you want to add feedback. Below are two methods to obtain this identifier.
39
27
@@ -64,22 +52,14 @@ In the example below, the `cf-aig-log-id` is `01JADMCQQQBWH3NXZ5GCRN98DP`.
64
52
65
53
If you do not have the `cf-aig-log-id` in the response body or you need to access it after the fact, you are able to retrieve it by querying the logs using the [Cloudflare API](/api/resources/ai_gateway/subresources/logs/methods/list/).
66
54
67
-
The steps below outline how to do this.
68
-
69
-
1.**Send a GET Request to Retrieve Logs**: You can query the AI Gateway logs for a specific time frame or for a specific request. The request will return a list of logs, each containing its own `id`.
70
-
Here is an example request:
71
-
72
-
```bash
73
-
GET https://api.cloudflare.com/client/v4/accounts/{account_id}/ai-gateway/gateways/{gateway_id}/logs
74
-
```
55
+
Send a `GET` request to get a list of logs and then find a specific ID
75
56
76
-
Replace `{account_id}` and `{gateway_id}` with your specific account and gateway details.
2.**Search for the Relevant Log**: In the response from the GET request, locate the specific log entry for which you would like to submit feedback. Each log entry will include the `id`.
79
-
80
-
In the example below, the `id` is `01JADMCQQQBWH3NXZ5GCRN98DP`.
81
-
82
-
```json
62
+
```json output
83
63
{
84
64
"result": [
85
65
{
@@ -103,24 +83,7 @@ In the example below, the `id` is `01JADMCQQQBWH3NXZ5GCRN98DP`.
103
83
"tokens_in": 0,
104
84
"tokens_out": 0
105
85
}
106
-
],
107
-
"result_info": {
108
-
"count": 0,
109
-
"max_cost": 0,
110
-
"max_duration": 0,
111
-
"max_tokens_in": 0,
112
-
"max_tokens_out": 0,
113
-
"max_total_tokens": 0,
114
-
"min_cost": 0,
115
-
"min_duration": 0,
116
-
"min_tokens_in": 0,
117
-
"min_tokens_out": 0,
118
-
"min_total_tokens": 0,
119
-
"page": 0,
120
-
"per_page": 0,
121
-
"total_count": 0
122
-
},
123
-
"success": true
86
+
]
124
87
}
125
88
```
126
89
@@ -129,42 +92,40 @@ In the example below, the `id` is `01JADMCQQQBWH3NXZ5GCRN98DP`.
129
92
You can also retrieve the `cf-aig-log-id` using a binding, which streamlines the process. Here's how to retrieve the log ID directly:
The `aiGatewayLogId` property, will only hold the last inference call log id.
147
113
148
-
149
114
:::
150
115
151
-
## 4. Submit feedback via PATCH request
116
+
## 3. Submit feedback via PATCH request
152
117
153
-
Once you have both the API token and the `cf-aig-log-id`, you can send a PATCH request to submit feedback. Use the following URL format, replacing the `{account_id}`, `{gateway_id}`, and `{log_id}` with your specific details:
118
+
Once you have both the API token and the `cf-aig-log-id`, you can send a PATCH request to submit feedback.
0 commit comments