(
request: HttpClientRequest.HttpClientRequest,
schema: Schema.Schema<A, I, R>
)
| 102 | }) |
| 103 | |
| 104 | const streamRequest = <A, I, R>( |
| 105 | request: HttpClientRequest.HttpClientRequest, |
| 106 | schema: Schema.Schema<A, I, R> |
| 107 | ): Stream.Stream<A, AiError.AiError, R> => { |
| 108 | const decodeEvents = Schema.decode(Schema.ChunkFromSelf(Schema.parseJson(schema))) |
| 109 | return httpClientOk.execute(request).pipe( |
| 110 | Effect.map((r) => r.stream), |
| 111 | Stream.unwrap, |
| 112 | Stream.decodeText(), |
| 113 | Stream.pipeThroughChannel(Sse.makeChannel()), |
| 114 | Stream.mapChunksEffect((chunk) => decodeEvents(Chunk.map(chunk, (event) => event.data))), |
| 115 | Stream.catchTags({ |
| 116 | RequestError: (error) => |
| 117 | AiError.HttpRequestError.fromRequestError({ |
| 118 | module: "GoogleClient", |
| 119 | method: "streamRequest", |
| 120 | error |
| 121 | }), |
| 122 | ResponseError: (error) => |
| 123 | AiError.HttpResponseError.fromResponseError({ |
| 124 | module: "GoogleClient", |
| 125 | method: "streamRequest", |
| 126 | error |
| 127 | }), |
| 128 | ParseError: (error) => |
| 129 | AiError.MalformedOutput.fromParseError({ |
| 130 | module: "GoogleClient", |
| 131 | method: "streamRequest", |
| 132 | error |
| 133 | }) |
| 134 | }) |
| 135 | ) |
| 136 | } |
| 137 | |
| 138 | const generateContent: ( |
| 139 | request: typeof Generated.GenerateContentRequest.Encoded |
no test coverage detected