Skip to content

Commit 6bae1ab

Browse files
Initial documentation on Feedback via Workers bindings
1 parent 28cb6c1 commit 6bae1ab

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+
## 3. 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, // both 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`: A boolean-like value (0 or 1) indicating whether the response was satisfactory.
49+
- `score`: An integer representing the quality or usefulness of the response.
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)