Skip to content

Commit 1919631

Browse files
daisyfaithaumahyperlint-ai[bot]
authored andcommitted
[AIG]Evaluations and Logging (#17134)
* Evaluations and Logging * Update src/content/docs/ai-gateway/observability/evaluations/set-up-evaluations.mdx Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com> * Links --------- Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
1 parent eb9081a commit 1919631

File tree

7 files changed

+142
-15
lines changed

7 files changed

+142
-15
lines changed

src/content/docs/ai-gateway/observability/analytics.mdx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Analytics and logging
2+
title: Analytics
33
pcx_content_type: reference
44
---
55

@@ -42,12 +42,3 @@ curl https://api.cloudflare.com/client/v4/graphql \
4242
```
4343
4444
</TabItem> </Tabs>
45-
46-
:::note[Note]
47-
48-
The cost metric is an estimation based on the number of tokens sent and received in requests. While this metric can help you monitor and predict cost trends, refer to your provider’s dashboard for the most accurate cost details.
49-
:::
50-
51-
## Logging
52-
53-
Your AI Gateway dashboard also shows real-time logs of individual requests, such as the prompt, response, provider, timestamps, and whether the request was successful, cached, or if there was an error. These logs now persist and can store up to 10,000 logs per gateway for better observability and analysis.

src/content/docs/ai-gateway/observability/costs.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
title: Costs
33
pcx_content_type: reference
4+
sidebar:
5+
order: 2
46
---
57

6-
78
## Supported Providers
89

910
AI Gateway currently supports cost metrics from the following providers:
@@ -28,7 +29,6 @@ The cost metric is an **estimation** based on the number of tokens sent and rece
2829

2930
:::caution[Caution]
3031

31-
3232
Providers may introduce new models or change their pricing. If you notice outdated cost data or are using a model not yet supported by our cost tracking, please [submit a request](https://forms.gle/8kRa73wRnvq7bxL48)
3333

3434
:::
@@ -37,6 +37,3 @@ Providers may introduce new models or change their pricing. If you notice outdat
3737

3838
AI Gateway allows users to set custom costs when operating under special pricing agreements or negotiated rates. Custom costs can be applied at the request level, and when applied, they will override the default or public model costs.
3939
For more information on configuration of custom costs, please visit the [Custom Costs](/ai-gateway/configuration/custom-costs/) configuration page.
40-
41-
42-
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Evaluations
3+
pcx_content_type: navigation
4+
order: 1
5+
---
6+
7+
Understanding your application's performance is essential for optimization. Developers often have different priorities, and finding the optimal solution involves balancing key factors such as cost, latency, and accuracy. Some prioritize low-latency responses, while others focus on accuracy or cost-efficiency.
8+
9+
AI Gateway's Evaluations provide the data needed to make informed decisions on how to optimize your AI application. Whether it's adjusting the model, provider, or prompt, this feature delivers insights into key metrics around performance, speed, and cost. It empowers developers to better understand their application's behavior, ensuring improved accuracy, reliability, and customer satisfaction.
10+
11+
Evaluations use datasets which are collections of logs stored for analysis. You can create datasets by applying filters in the Logs tab, which help narrow down specific logs for evaluation.
12+
13+
Our first step toward comprehensive AI evaluations starts with human feedback (currently in open beta). We will continue to build and expand AI Gateway with additional evaluators.
14+
15+
[Learn how to set up an evaluation](/ai-gateway/observability/evaluations/set-up-evaluations/) including creating datasets, selecting evaluators, and running the evaluation process.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
pcx_content_type: how-to
3+
title: Set up Evaluations
4+
sidebar:
5+
order: 2
6+
---
7+
8+
This guide walks you through the process of setting up an evaluation in AI Gateway. These steps are done in the [Cloudflare dashboard](https://dash.cloudflare.com/).
9+
10+
## 1. Select or create a dataset
11+
12+
Datasets are collections of logs stored for analysis that can be used in an evaluation. You can create datasets by applying filters in the Logs tab. Datasets will update automatically based on the set filters.
13+
14+
### Set up a dataset from the Logs tab
15+
16+
1. Apply filters to narrow down your logs. Filter options include provider, number of tokens, request status, and more.
17+
2. Select **Create Dataset** to store the filtered logs for future analysis.
18+
19+
You can manage datasets by selecting **Manage datasets** from the Logs tab.
20+
21+
:::note[Note]
22+
23+
Please keep in mind that datasets currently use `AND` joins, so there can only be one item per filter (for example, one model or one provider). Future updates will allow more flexibility in dataset creation.
24+
25+
:::
26+
27+
## 2. Select evaluators
28+
29+
After creating a dataset, choose the evaluation parameters:
30+
31+
- Cost: Calculates the average cost of inference requests within the dataset (only for requests with [cost data](/ai-gateway/observability/costs/)).
32+
- Speed: Calculates the average duration of inference requests within the dataset.
33+
- Performance:
34+
- Human feedback: measures performance based on human feedback, calculated by the % of thumbs up on the logs, annotated from the Logs tab.
35+
36+
:::note[Note]
37+
38+
Additional evaluators will be introduced in future updates to expand performance analysis capabilities.
39+
40+
:::
41+
42+
## 3. Name, review, and run the evaluation
43+
44+
1. Create a unique name for your evaluation to reference it in the dashboard.
45+
2. Review the selected dataset and evaluators.
46+
3. Select **Run** to start the process.
47+
48+
## 4. Review and analyze results
49+
50+
Evaluation results will appear in the Evaluations tab. The results show the status of the evaluation (for example, in progress, completed, or error). Metrics for the selected evaluators will be displayed, excluding any logs with missing fields. You will also see the number of logs used to calculate each metric.
51+
52+
While datasets automatically update based on filters, evaluations do not. You will have to create a new evaluation if you want to evaluate new logs.
53+
54+
Use these insights to optimize based on your application's priorities. Based on the results, you may choose to:
55+
56+
- Change the model or [provider](/ai-gateway/providers/)
57+
- Adjust your prompts
58+
- Explore further optimizations, such as setting up [Retrieval Augmented Generation (RAG)](/reference-architecture/diagrams/ai/ai-rag/)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
pcx_content_type: reference
3+
title: Logging
4+
sidebar:
5+
badge:
6+
text: Beta
7+
---
8+
9+
import { Render } from "~/components";
10+
11+
Logging is a fundamental building block for application development. Logs provide insights during the early stages of development and are often critical to understanding issues occurring in production.
12+
13+
Your AI Gateway dashboard shows logs of individual requests, including the user prompt, model response, provider, timestamp, request status, token usage, cost, and duration. These logs persist, giving you the flexibility to store them for your preferred duration and do more with valuable request data.
14+
15+
You can store up to 10 million logs per gateway. If your limit is reached, new logs will stop being saved. To continue saving logs, you must delete older logs to free up space for new logs.
16+
17+
To learn more about your plan limits, refer to [Pricing](/ai-gateway/pricing/).
18+
19+
## Default configuration
20+
21+
Logs, which include metrics as well as request and response data, are enabled by default for each gateway. This logging behavior will be uniformly applied to all requests in the gateway. If you are concerned about privacy or compliance and want to turn log collection off, you can go to settings and opt out of logs. If you need to modify the log settings for specific requests, you can override this setting on a per-request basis.
22+
23+
<Render file="logging" />
24+
25+
:::note
26+
27+
To export logs using [Logpush](/ai-gateway/observability/logging/logpush), you must have logs turned on for the gateway.
28+
29+
:::
30+
31+
## Per-request logging
32+
33+
To override the default logging behavior set in the settings tab, you can define headers on a per-request basis.
34+
35+
## Collect logs (`cf-aig-collect-log`)
36+
37+
The `cf-aig-collect-log` header allows you to bypass the default log setting for the gateway. If the gateway is configured to save logs, the header will exclude the log for that specific request. Conversely, if logging is disabled at the gateway level, this header will save the log for that request.
38+
39+
In the example below, we use `cf-aig-collect-log` to bypass the default setting to avoid saving the log.
40+
41+
```bash
42+
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
43+
--header 'Authorization: Bearer $TOKEN' \
44+
--header 'Content-Type: application/json' \
45+
--header 'cf-aig-collect-log: false \
46+
--data ' {
47+
"model": "gpt-4o-mini",
48+
"messages": [
49+
{
50+
"role": "user",
51+
"content": "What is the email address and phone number of user123?"
52+
}
53+
]
54+
}
55+
'
56+
```
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
{}
3+
---
4+
5+
To change the default log configuration in the dashboard:
6+
7+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and select your account.
8+
2. Go to **AI** > **AI Gateway**.
9+
3. Select **Settings**.
10+
4. Change the **Logs** setting to your preference.

0 commit comments

Comments
 (0)