Skip to content

Commit

Permalink
refactor(playground): use composer.send (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 8, 2024
1 parent 600e9ab commit 6b0a561
Showing 1 changed file with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,14 @@ const RoleSelect: FC<RoleSelectProps> = ({ role, setRole, children }) => {

const Composer: FC = () => {
const [role, setRole] = useState<"user" | "assistant" | "system">("user");
const { useThread, useThreadActions, useComposer, useThreadMessages } =
useThreadContext();
const { useThread, useThreadActions, useComposer } = useThreadContext();

const isRunning = useThread((t) => t.isRunning);
const hasText = useComposer((c) => c.text.length > 0);

const performAdd = () => {
const composer = useComposer.getState();
const text = composer.text;
if (!text) return;

composer.reset();

useThreadActions.getState().append({
parentId: useThreadMessages.getState().at(-1)?.id ?? null,
role,
content: [{ type: "text", text }],
attachments: composer.attachments,
});
composer.send();

setRole("user");
};
Expand Down

0 comments on commit 6b0a561

Please sign in to comment.