Skip to content

Commit

Permalink
refactor: remove useGetPlaygroundRuntime (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Sep 22, 2024
1 parent 1a99132 commit 3970adc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-toys-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react-playground": patch
---

refactor: remove useGetPlaygroundRuntime
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
requestOptionsFromOpenAI,
requestOptionsToOpenAI,
} from "../lib/converters";
import { useGetPlaygroundRuntime } from "../lib/usePlaygroundRuntime";
import { toCoreMessages, toLanguageModelTools } from "@assistant-ui/react";
import { JSONEditor } from "./ui/assistant-ui/json-editor";
import { TooltipIconButton } from "./ui/assistant-ui/tooltip-icon-button";
import { EyeIcon } from "lucide-react";
import { usePlaygroundRuntime } from "../lib/usePlaygroundRuntime";

export const PayloadEditorButton: FC = () => {
const getPlaygroundRuntime = useGetPlaygroundRuntime();
const runtime = usePlaygroundRuntime();

const [isOpen, setIsOpen] = useState(false);
const [value, setValue] = useState("");
Expand All @@ -29,7 +29,6 @@ export const PayloadEditorButton: FC = () => {
setIsOpen(open);
if (!open) return;

const runtime = getPlaygroundRuntime();
const config = runtime.useModelConfig.getState();
const options: EdgeRuntimeRequestOptions = {
modelName: config.config?.modelName ?? "gpt-4o",
Expand All @@ -51,7 +50,7 @@ export const PayloadEditorButton: FC = () => {
}

const options = requestOptionsFromOpenAI(jsonValue);
getPlaygroundRuntime().setRequestData(options);
runtime.setRequestData(options);
setIsOpen(false);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { useContentPartStore, useMessageStore } from "@assistant-ui/react";
import { TooltipIconButton } from "./tooltip-icon-button";
import { CircleXIcon } from "lucide-react";
import { FC } from "react";
import { useGetPlaygroundRuntime } from "../../../lib/usePlaygroundRuntime";
import { usePlaygroundRuntime } from "../../../lib/usePlaygroundRuntime";

export const RemoveContentPartButton: FC = () => {
const getPlaygroundRuntime = useGetPlaygroundRuntime();
const runtime = usePlaygroundRuntime();

const messageStore = useMessageStore();
const contentPartStore = useContentPartStore();
const handleRemove = () => {
getPlaygroundRuntime().deleteContentPart(
runtime.deleteContentPart(
messageStore.getState().message.id,
contentPartStore.getState().part,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ import {
DropdownMenuLabel,
DropdownMenuTrigger,
} from "../dropdown-menu";
import {
useGetPlaygroundRuntime,
usePlaygroundRuntime,
} from "../../../lib/usePlaygroundRuntime";
import { usePlaygroundRuntime } from "../../../lib/usePlaygroundRuntime";
import { ToolUI } from "./tool-ui";
import { Text } from "./text";
import {
Expand Down Expand Up @@ -222,13 +219,13 @@ const AddToolCallButton = () => {
};

const AddImageButton = () => {
const getPlaygroundRuntime = useGetPlaygroundRuntime();
const runtime = usePlaygroundRuntime();
const messageStore = useMessageStore();

const [isOpen, setIsOpen] = useState(false);
const [imageUrl, setImageUrl] = useState("");
const handleAddImage = () => {
getPlaygroundRuntime().addImage({
runtime.addImage({
image: new URL(imageUrl).href,
messageId: messageStore.getState().message.id,
});
Expand Down Expand Up @@ -264,19 +261,19 @@ const AddImageButton = () => {
};

const Message: FC = () => {
const getPlaygroundRuntime = useGetPlaygroundRuntime();
const runtime = usePlaygroundRuntime();
const messageStore = useMessageStore();
const role = useMessage((m) => m.message.role);
const status = useMessage((m) =>
m.message.role === "assistant" ? m.message.status : null,
);

const handleDelete = () => {
getPlaygroundRuntime().deleteMessage(messageStore.getState().message.id);
runtime.deleteMessage(messageStore.getState().message.id);
};

const setRole = (role: "system" | "assistant" | "user") => {
getPlaygroundRuntime().setRole({
runtime.setRole({
messageId: messageStore.getState().message.id,
role,
});
Expand Down
6 changes: 1 addition & 5 deletions packages/react-playground/src/lib/usePlaygroundRuntime.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"use client";
import { useThreadRuntime, useThreadRuntimeStore } from "@assistant-ui/react";
import { useThreadRuntime } from "@assistant-ui/react";
import { PlaygroundThreadRuntime } from "./playground-runtime";

export const useGetPlaygroundRuntime = () => {
return useThreadRuntimeStore().getState as () => PlaygroundThreadRuntime;
};

export const usePlaygroundRuntime = () => {
return useThreadRuntime() as PlaygroundThreadRuntime;
};

0 comments on commit 3970adc

Please sign in to comment.