Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions apps/ai/src/platform/Llm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,55 @@ describe("layerDecisionModel — Clef on Workers AI", () => {
assert.strictEqual(captured.body.model, "clef-flash")
}),
)

it.live("sends score levels as descriptions and keys the answer's probabilities by label", () =>
Effect.gen(function* () {
const severity = Decision.make({
input: Schema.Struct({ message: Schema.String }),
decisions: {
severity: Decision.rate({
instructions: "How urgent is this incident",
criteria: [
{ label: "low", description: "Cosmetic, no user impact" },
{ label: "medium", description: "Degraded for some users" },
{ label: "high", description: "Outage or data loss" },
],
}),
},
})
let questions: unknown
const fakeFetch: typeof globalThis.fetch = async (_input, init) => {
const body = JSON.parse(await new Response(init?.body ?? "{}").text()) as Record<
string,
unknown
>
questions = body.questions
const answer = { type: "score", score: 2, probabilities: { "0": 0.1, "1": 0.2, "2": 0.7 } }
const output = { answers: { severity: answer }, usage: { input_tokens: 1, output_tokens: 1 } }
return new Response(JSON.stringify({ result: output }), { status: 200 })
}

const response = yield* DecisionModel.decide(severity, { input: { message: "db down" } }).pipe(
Effect.provide(layerDecisionModel(workersAiEnv)),
Effect.provideService(FetchHttpClient.Fetch, fakeFetch),
)

assert.deepStrictEqual(questions, {
severity: {
type: "score",
instructions: "How urgent is this incident",
criteria: ["Cosmetic, no user impact", "Degraded for some users", "Outage or data loss"],
},
})
assert.strictEqual(response.answers.severity.rating, 2)
assert.strictEqual(response.answers.severity.label, "high")
assert.deepStrictEqual(response.answers.severity.probabilities, {
low: 0.1,
medium: 0.2,
high: 0.7,
})
}),
)
})

describe("loadLlmSettings", () => {
Expand Down
15 changes: 10 additions & 5 deletions apps/ai/src/platform/WorkersAiDecisionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
import { Effect, Layer, Schema } from "effect"
import * as AiError from "effect/ai/AiError"
import type * as Decision from "effect/ai/Decision"
import * as DecisionModel from "effect/ai/DecisionModel"
import { HttpClient, HttpClientError, HttpClientRequest, HttpClientResponse } from "effect/http"

Expand Down Expand Up @@ -40,9 +41,13 @@ const ClefOutput = Schema.Struct({
const ClefResponse = Schema.Union([Schema.Struct({ result: ClefOutput }), ClefOutput])

type ClefQuestion =
| { readonly type: "noul"; readonly instructions: string; readonly criteria: unknown }
| { readonly type: "choice"; readonly instructions: string; readonly criteria: unknown }
| { readonly type: "score"; readonly instructions: string; readonly criteria: ReadonlyArray<string> }
| { readonly type: "noul"; readonly instructions: Decision.Description; readonly criteria: unknown }
| { readonly type: "choice"; readonly instructions: Decision.Description; readonly criteria: unknown }
| {
readonly type: "score"
readonly instructions: Decision.Description
readonly criteria: ReadonlyArray<Decision.Description>
}

/** `@cf/cloudflare/clef-flash` → `clef-flash`: the body names the variant, the URL the model. */
const variantOf = (model: string): string => model.slice(model.lastIndexOf("/") + 1)
Expand Down Expand Up @@ -90,7 +95,7 @@ export const make = Effect.fnUntraced(function* (options: {
questions[key] = {
type: "score",
instructions: decision.instructions,
criteria: decision.criteria,
criteria: decision.criteria.map((level) => level.description),
}
break
case "Probability":
Expand Down Expand Up @@ -143,7 +148,7 @@ export const make = Effect.fnUntraced(function* (options: {
const decision = decisions[key]
const probabilities: Record<string, number> = {}
if (decision?._tag === "Rate") {
for (const [index, label] of decision.criteria.entries()) {
for (const [index, { label }] of decision.criteria.entries()) {
const probability = answer.probabilities[String(index)]
if (probability !== undefined) probabilities[label] = probability
}
Expand Down
16 changes: 14 additions & 2 deletions apps/cli/src/core/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,20 @@ const makeTelemetryLayer = Effect.gen(function* () {
}
const headers = { Authorization: `Bearer ${Redacted.value(key)}` }
return Layer.mergeAll(
OtlpTracer.layer({ url: `${endpoint}/v1/traces`, resource, headers, shutdownTimeout: "3 seconds" }),
OtlpMetrics.layer({ url: `${endpoint}/v1/metrics`, resource, headers, shutdownTimeout: "3 seconds" }),
OtlpTracer.layer({
url: `${endpoint}/v1/traces`,
resource,
headers,
compression: "gzip",
shutdownTimeout: "3 seconds",
}),
OtlpMetrics.layer({
url: `${endpoint}/v1/metrics`,
resource,
headers,
compression: "gzip",
shutdownTimeout: "3 seconds",
}),
).pipe(Layer.provide(ScrubbedSerialization), Layer.provide(FetchHttpClient.layer))
})

Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@clerk/themes": "^2.4.57",
"@effect/platform-browser": "4.0.4",
"@effect/platform-browser": "4.0.5",
"@floating-ui/dom": "1.8.0",
"@foldkit/markdown": "0.14.4",
"@foldkit/ui": "0.169.0",
Expand Down
60 changes: 30 additions & 30 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@changesets/cli": "3.0.3",
"@cloudflare/workers-types": "catalog:alchemy",
"@effect/platform-node": "catalog:effect",
"@effect/sql-pg": "4.0.4",
"@effect/sql-pg": "4.0.5",
"@effect/tsgo": "0.48.1",
"@effect/vitest": "catalog:effect",
"@maple-dev/effect-orm": "0.5.0",
Expand All @@ -87,9 +87,9 @@
"vitest": "catalog:"
},
"overrides": {
"@effect/platform-browser": "4.0.4",
"@effect/sql-d1": "4.0.4",
"@effect/sql-sqlite-do": "4.0.4",
"@effect/platform-browser": "4.0.5",
"@effect/sql-d1": "4.0.5",
"@effect/sql-sqlite-do": "4.0.5",
"workerd": "1.20261002.1"
},
"packageManager": "bun@1.4.0",
Expand All @@ -109,14 +109,14 @@
"@tanstack/charts-scales": "1.0.0"
},
"effect": {
"@effect/ai-openai-compat": "4.0.4",
"@effect/ai-openrouter": "4.0.4",
"@effect/atom-react": "4.0.4",
"@effect/ai-openai-compat": "4.0.5",
"@effect/ai-openrouter": "4.0.5",
"@effect/atom-react": "4.0.5",
"@effect/language-service": "^0.87.4",
"@effect/platform-bun": "4.0.4",
"@effect/platform-node": "4.0.4",
"@effect/vitest": "4.0.4",
"effect": "4.0.4"
"@effect/platform-bun": "4.0.5",
"@effect/platform-node": "4.0.5",
"@effect/vitest": "4.0.5",
"effect": "4.0.5"
},
"react": {
"@types/react": "^19.3.0",
Expand All @@ -142,9 +142,9 @@
}
},
"patchedDependencies": {
"@effect/ai-openrouter@4.0.4": "patches/@effect%2Fai-openrouter@4.0.4.patch",
"@effect/vitest@4.0.4": "patches/@effect%2Fvitest@4.0.4.patch",
"effect@4.0.4": "patches/effect@4.0.4.patch",
"@effect/ai-openrouter@4.0.5": "patches/@effect%2Fai-openrouter@4.0.5.patch",
"@effect/vitest@4.0.5": "patches/@effect%2Fvitest@4.0.5.patch",
"effect@4.0.5": "patches/effect@4.0.5.patch",
"@cloudflare/workers-types@5.20261005.1": "patches/@cloudflare%2Fworkers-types@5.20261005.1.patch",
"alchemy@2.0.0-beta.83": "patches/alchemy@2.0.0-beta.83.patch"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"db:backfill:dashboards-v3": "bun scripts/backfill-dashboard-datasource-v3.ts"
},
"dependencies": {
"@effect/sql-pg": "4.0.4",
"@effect/sql-pglite": "4.0.4",
"@effect/sql-pg": "4.0.5",
"@effect/sql-pglite": "4.0.5",
"@electric-sql/pglite": "^0.5.8",
"@maple/domain": "workspace:*",
"@maple-dev/effect-orm": "0.5.0",
Expand Down
Loading
Loading