import { generateObject, jsonSchema } from "ai"
import { Array, Data, Effect, JSONSchema, Schema, Stream } from "effect"
export class AiPlanningError extends Data.TaggedError("@app/AiPlanningError")<{
cause: unknown
}> {}
const AiResponseSchema = Schema.Struct({
startDate: Schema.String.pipe(
Schema.annotations({
description: "The new start date of the event, in ISO format",
examples: ["2025-11-17T12:00:00+01:00"]
})
),
endDate: Schema.String.pipe(
Schema.annotations({
description: "The new end date of the event, in ISO format",
examples: ["2025-12-01T12:00:00+01:00"]
})
)
})
const program = Effect.gen(function*() {
const AiResponseJsonSchema = JSONSchema.make(AiResponseSchema)
const result = yield* Effect.tryPromise({
try: (signal) =>
generateObject({
abortSignal: signal,
model: "openai/gpt-4o",
output: "object",
schema: jsonSchema(AiResponseJsonSchema),
messages: [
{
role: "system",
content:
"Bla bla bla"
},
{
role: "user",
content: `Bitte analysiere die historischen Daten für das Seminar.`
}
]
}),
catch: (error) => new AiPlanningError({ cause: error })
})
})
import { generateObject, jsonSchema } from "ai"
import { Array, Data, Effect, JSONSchema, Schema, Stream } from "effect"
export class AiPlanningError extends Data.TaggedError("@app/AiPlanningError")<{
cause: unknown
}> {}
const AiResponseSchema = Schema.Struct({
startDate: Schema.String.pipe(
Schema.annotations({
description: "The new start date of the event, in ISO format",
examples: ["2025-11-17T12:00:00+01:00"]
})
),
endDate: Schema.String.pipe(
Schema.annotations({
description: "The new end date of the event, in ISO format",
examples: ["2025-12-01T12:00:00+01:00"]
})
)
})
const program = Effect.gen(function*() {
const AiResponseJsonSchema = JSONSchema.make(AiResponseSchema)
const result = yield* Effect.tryPromise({
try: (signal) =>
generateObject({
abortSignal: signal,
model: "openai/gpt-4o",
output: "object",
schema: jsonSchema(AiResponseJsonSchema),
messages: [
{
role: "system",
content:
"Bla bla bla"
},
{
role: "user",
content: `Bitte analysiere die historischen Daten für das Seminar.`
}
]
}),
catch: (error) => new AiPlanningError({ cause: error })
})
})