Skip to content

Commit

Permalink
Allow preResponseCallback and preResponseChunkCallback to return void (
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 authored Apr 22, 2024
1 parent f065ebf commit b14c8e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ declare module 'fastify' {
ai: {
warp: (request: FastifyRequest, prompt: string) => Promise<string>
warpStream: (request: FastifyRequest, prompt: string) => Promise<ReadableStream>
preResponseCallback?: ((request: FastifyRequest, response: string) => string) | ((request: FastifyRequest, response: string) => Promise<string>)
preResponseChunkCallback?: ((request: FastifyRequest, response: string) => string) | ((request: FastifyRequest, response: string) => Promise<string>)
preResponseCallback?: ((request: FastifyRequest, response: string) => void) |
((request: FastifyRequest, response: string) => string) |
((request: FastifyRequest, response: string) => Promise<void>) |
((request: FastifyRequest, response: string) => Promise<string>)
preResponseChunkCallback?: ((request: FastifyRequest, response: string) => void) |
((request: FastifyRequest, response: string) => string) |
((request: FastifyRequest, response: string) => Promise<void>) |
((request: FastifyRequest, response: string) => Promise<string>)
rateLimiting: {
max?: ((req: FastifyRequest, key: string) => number) | ((req: FastifyRequest, key: string) => Promise<number>)
allowList?: (req: FastifyRequest, key: string) => boolean | Promise<boolean>
Expand Down
4 changes: 2 additions & 2 deletions plugins/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default fastifyPlugin(async (fastify) => {

let response = await provider.ask(decoratedPrompt)
if (fastify.ai.preResponseCallback !== undefined) {
response = await fastify.ai.preResponseCallback(request, response)
response = await fastify.ai.preResponseCallback(request, response) ?? response
}

return response
Expand All @@ -57,7 +57,7 @@ export default fastifyPlugin(async (fastify) => {
if (fastify.ai.preResponseChunkCallback === undefined) {
return response
}
return await fastify.ai.preResponseChunkCallback(request, response)
return await fastify.ai.preResponseChunkCallback(request, response) ?? response
}
}

Expand Down

0 comments on commit b14c8e3

Please sign in to comment.