Skip to content

Commit

Permalink
feat: add appendAtom in chatAtoms
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Sep 12, 2024
1 parent c663f6f commit 0792f8c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/jotai-ai/src/chatAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ export function chatAtoms(
set(inputBaseAtom, event.target.value);
},
),
appendAtom: atom(
(get) => get(isLoadingAtom),
async (
get,
set,
message: Message | CreateMessage,
options: ChatRequestOptions = {},
metadata?: Metadata,
) => {
if (metadata) {
set(metadataAtom, (prevMetadata) => ({
...prevMetadata,
...metadata,
}));
}
return append(get, set, message, options).catch((err) =>
onError(get, set, err),
);
},
),
submitAtom: atom(
(get) => get(isLoadingAtom),
(
Expand Down

0 comments on commit 0792f8c

Please sign in to comment.