-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fromCoreMessages converter (#477)
- Loading branch information
Showing
6 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/react/src/runtimes/edge/converters/fromCoreMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { generateId } from "../../../internal"; | ||
import { ThreadMessage, CoreMessage } from "../../../types"; | ||
|
||
export const fromCoreMessages = (message: CoreMessage[]): ThreadMessage[] => { | ||
return message.map((message) => { | ||
return { | ||
...message, | ||
id: generateId(), | ||
createdAt: new Date(), | ||
...(message.role === "assistant" | ||
? { | ||
status: { type: "done" }, | ||
} | ||
: undefined), | ||
} as ThreadMessage; | ||
}); | ||
}; |
11 changes: 0 additions & 11 deletions
11
packages/react/src/runtimes/edge/converters/toCoreMessage.ts
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
packages/react/src/runtimes/edge/converters/toCoreMessages.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ThreadMessage, CoreMessage } from "../../../types"; | ||
|
||
export const toCoreMessages = (message: ThreadMessage[]): CoreMessage[] => { | ||
return message.map((message) => { | ||
return { | ||
role: message.role, | ||
content: message.content.map((part) => { | ||
if (part.type === "ui") throw new Error("UI parts are not supported"); | ||
return part; | ||
}), | ||
} as CoreMessage; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters