Skip to content

Commit

Permalink
Support newer replicate versions, fix onResponse callback when no onC…
Browse files Browse the repository at this point in the history
…ompletion is passed (#631)

Co-authored-by: Max Leiter <max.leiter@vercel.com>
  • Loading branch information
peterdresslar and MaxLeiter committed Oct 11, 2023
1 parent 385bdcd commit c5d1857
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-fishes-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

fix: return complete response in onFinish when onCompletion isn't passed
5 changes: 5 additions & 0 deletions .changeset/friendly-elephants-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

replicate-stream: fix types for replicate@0.20.0+
2 changes: 1 addition & 1 deletion examples/next-replicate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"next": "13.4.12",
"react": "18.2.0",
"react-dom": "^18.2.0",
"replicate": "^0.16.0"
"replicate": "^0.20.1"
},
"devDependencies": {
"@types/node": "^17.0.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/streams/ai-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export function createCallbacksTransformer(
async transform(message, controller): Promise<void> {
controller.enqueue(textEncoder.encode(message));

aggregatedResponse += message;
if (callbacks.onToken) await callbacks.onToken(message);
if (callbacks.onCompletion) aggregatedResponse += message;
},

async flush(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/streams/replicate-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Prediction {
webhook?: string;
webhook_events_filter?: ('start' | 'output' | 'logs' | 'completed')[];
created_at: string;
updated_at: string;
updated_at?: string;
completed_at?: string;
urls: {
get: string;
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

0 comments on commit c5d1857

Please sign in to comment.