Skip to content

Commit 7da4556

Browse files
committed
fix(ai): report Clef's own rounding on Workers AI
1 parent 248f751 commit 7da4556

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎packages/ai/src/experimental/cloudflare-run-evaluation.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { Effect, Schema } from "effect"
2-
import { EvaluationModel, type EvaluationRequestFor, type EvaluationResponse } from "./evaluation.js"
2+
import {
3+
EvaluationModel,
4+
type EvaluationRequestFor,
5+
type EvaluationResponse,
6+
type EvaluationRounding,
7+
} from "./evaluation.js"
38
import { SystemOne } from "./system-one.js"
49
import { Endpoint } from "../route/endpoint.js"
510
import { MediaProtocol } from "../route/media-protocol.js"
@@ -20,6 +25,7 @@ export interface ModelInput extends MediaRoute.ModelInput {
2025
readonly provider: ProviderID
2126
/** The Run API base, `.../client/v4/accounts/{account}/ai/run`. */
2227
readonly baseURL: string
28+
readonly rounding?: EvaluationRounding
2329
}
2430

2531
/** Posts `{ model, input }` to Cloudflare's `/ai/run` with the System One request body as `input`. */
@@ -45,7 +51,7 @@ export const model = (input: ModelInput) => {
4551
SystemOne.toResponse(
4652
"answers" in output.value.result ? output.value.result : output.value.result.result,
4753
input.provider,
48-
SystemOne.jevRounding,
54+
input.rounding,
4955
),
5056
),
5157
),

‎packages/ai/src/providers/cloudflare-ai-gateway.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Config, Redacted } from "effect"
22
import type { ProviderPackage } from "../provider-package.js"
33
import { CloudflareRunEvaluation } from "../experimental/cloudflare-run-evaluation.js"
4+
import { SystemOne } from "../experimental/system-one.js"
45
import { AnthropicMessages, OpenAIChat, OpenAIResponses } from "../protocols/index.js"
56
import { Auth } from "../route/auth.js"
67
import { Endpoint } from "../route/endpoint.js"
@@ -139,6 +140,7 @@ export const configure = (input: LanguageModelOptions) => {
139140
baseURL: runBaseURL(input),
140141
headers: rest.headers,
141142
http: HttpOptions.make(input.http),
143+
rounding: SystemOne.jevRounding,
142144
})
143145
return {
144146
id,

‎packages/ai/src/providers/cloudflare-workers-ai.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ProviderPackage } from "../provider-package.js"
22
import { CloudflareRunEvaluation } from "../experimental/cloudflare-run-evaluation.js"
3+
import { EvaluationRounding } from "../experimental/evaluation.js"
34
import { OpenAIChat } from "../protocols/openai-chat.js"
45
import { AuthOptions, type AtLeastOne, type ProviderAuthOption } from "../route/auth-options.js"
56
import { Route, type RouteDefaultsInput } from "../route/client.js"
@@ -59,6 +60,8 @@ export const route = Route.make({
5960

6061
export const routes = [route]
6162

63+
const clefRounding = new EvaluationRounding({ probabilityDecimals: 4, scoreDecimals: 4 })
64+
6265
export const configure = (input: LanguageModelOptions) => {
6366
const { accountId: _accountId, apiKey: _apiKey, auth: _auth, baseURL: _baseURL, ...defaults } = input
6467
const auth = AuthOptions.bearer(input, authEnvVars)
@@ -71,6 +74,7 @@ export const configure = (input: LanguageModelOptions) => {
7174
baseURL: runBaseURL(input),
7275
headers: input.headers,
7376
http: HttpOptions.make(input.http),
77+
rounding: clefRounding,
7478
})
7579
return {
7680
id,

‎packages/ai/test/provider/evaluation.recorded.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ describe("experimental Evaluation recorded", () => {
155155
apiKey: process.env.CLOUDFLARE_API_KEY ?? "fixture",
156156
}).experimental.evaluation("@cf/cloudflare/clef"),
157157
"clef",
158+
).pipe(
159+
Effect.map((response) => expect(response.rounding).toMatchObject({ probabilityDecimals: 4, scoreDecimals: 4 })),
158160
),
159161
)
160162

@@ -164,6 +166,8 @@ describe("experimental Evaluation recorded", () => {
164166
accountId: process.env.CLOUDFLARE_ACCOUNT_ID ?? "fixture-account",
165167
gatewayApiKey: process.env.CLOUDFLARE_API_TOKEN ?? "fixture",
166168
}).experimental.evaluation("typesafe/jev"),
169+
).pipe(
170+
Effect.map((response) => expect(response.rounding).toMatchObject({ probabilityDecimals: 2, scoreDecimals: 2 })),
167171
),
168172
)
169173

0 commit comments

Comments
 (0)