Skip to content

Commit 9c60273

Browse files
[AIG]Initial documentation on Feedback via Workers bindings (#19899)
* Initial documentation on Feedback via Workers bindings * Update add-human-feedback-bindings.mdx steps * Update src/content/docs/ai-gateway/evaluations/add-human-feedback-bindings.mdx Co-authored-by: marciocloudflare <[email protected]> * minor fixes --------- Co-authored-by: marciocloudflare <[email protected]>
1 parent ae8fb66 commit 9c60273

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Add human feedback using Worker Bindings
4+
sidebar:
5+
order: 4
6+
---
7+
8+
This guide explains how to provide human feedback for AI Gateway evaluations using Worker bindings.
9+
10+
## 1. Run an AI Evaluation
11+
12+
Start by sending a prompt to the AI model through your AI Gateway.
13+
14+
```javascript
15+
const resp = await env.AI.run(
16+
"@cf/meta/llama-3.1-8b-instruct",
17+
{
18+
prompt: "tell me a joke",
19+
},
20+
{
21+
gateway: {
22+
id: "my-gateway",
23+
},
24+
},
25+
);
26+
27+
const myLogId = env.AI.aiGatewayLogId;
28+
```
29+
30+
Let the user interact with or evaluate the AI response. This interaction will inform the feedback you send back to the AI Gateway.
31+
32+
## 2. Send Human Feedback
33+
34+
Use the [`patchLog()`](/ai-gateway/integrations/worker-binding-methods/#31-patchlog-send-feedback) method to provide feedback for the AI evaluation.
35+
36+
```javascript
37+
await env.AI.gateway("my-gateway").patchLog(myLogId, {
38+
feedback: 1, // all fields are optional; set values that fit your use case
39+
score: 100,
40+
metadata: {
41+
user: "123", // Optional metadata to provide additional context
42+
},
43+
});
44+
```
45+
46+
## Feedback parameters explanation
47+
48+
- `feedback`: is either `-1` for negative or `1` to positive, `0` is considered not evaluated.
49+
- `score`: A number between 0 and 100.
50+
- `metadata`: An object containing additional contextual information.
51+
52+
### patchLog: Send Feedback
53+
54+
The `patchLog` method allows you to send feedback, score, and metadata for a specific log ID. All object properties are optional, so you can include any combination of the parameters:
55+
56+
```javascript
57+
gateway.patchLog("my-log-id", {
58+
feedback: 1,
59+
score: 100,
60+
metadata: {
61+
user: "123",
62+
},
63+
});
64+
```
65+
66+
Returns: `Promise<void>` (Make sure to `await` the request.)

0 commit comments

Comments
 (0)