MCPcopy Index your code
hub / github.com/Effect-TS/effect / streamRequest

Function streamRequest

packages/ai/google/src/GoogleClient.ts:104–136  ·  view source on GitHub ↗
(
      request: HttpClientRequest.HttpClientRequest,
      schema: Schema.Schema<A, I, R>
    )

Source from the content-addressed store, hash-verified

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

Callers 1

generateContentStreamFunction · 0.70

Calls 7

decodeMethod · 0.80
fromRequestErrorMethod · 0.80
fromResponseErrorMethod · 0.80
pipeMethod · 0.65
mapMethod · 0.65
executeMethod · 0.45
fromParseErrorMethod · 0.45

Tested by

no test coverage detected