Additional Demo Fixes (#191)

This commit is contained in:
Sylvie Crowe 2024-08-01 00:57:06 -07:00 committed by GitHub
parent 49a365e10b
commit 7cba3c46d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 32 additions and 5 deletions

View File

@ -3,6 +3,7 @@
import { useHeight } from "@/app/hook/useHeight";
import { useWidth } from "@/app/hook/useWidth";
import { WOS } from "@/store/global";
import { WshServer } from "@/store/wshserver";
import * as Plot from "@observablehq/plot";
import dayjs from "dayjs";
@ -28,9 +29,11 @@ class CpuPlotViewModel {
dataAtom: jotai.PrimitiveAtom<Array<Point>>;
addDataAtom: jotai.WritableAtom<unknown, [Point], void>;
width: number;
incrementCount: jotai.WritableAtom<unknown, [], Promise<void>>;
constructor(blockId: string) {
this.blockId = blockId;
this.blockAtom = WOS.getWaveObjectAtom<Block>(`block:${blockId}`);
this.width = 100;
this.dataAtom = jotai.atom(this.getDefaultData());
this.addDataAtom = jotai.atom(null, (get, set, point) => {
@ -45,6 +48,11 @@ class CpuPlotViewModel {
this.viewName = jotai.atom((get) => {
return "CPU %"; // should not be hardcoded
});
this.incrementCount = jotai.atom(null, async (get, set) => {
const meta = get(this.blockAtom).meta;
const count = meta.count ?? 0;
await WshServer.SetMetaCommand({ oref: WOS.makeORef("block", this.blockId), meta: { count: count + 1 } });
});
}
getDefaultData(): Array<Point> {
@ -69,6 +77,8 @@ function CpuPlotView({ model }: { model: CpuPlotViewModel }) {
const addPlotData = jotai.useSetAtom(model.addDataAtom);
const parentHeight = useHeight(containerRef);
const parentWidth = useWidth(containerRef);
const block = jotai.useAtomValue(model.blockAtom);
const incrementCount = jotai.useSetAtom(model.incrementCount); // temporary
React.useEffect(() => {
console.log("plotData:", plotData);
@ -76,8 +86,9 @@ function CpuPlotView({ model }: { model: CpuPlotViewModel }) {
React.useEffect(() => {
const temp = async () => {
await incrementCount();
const dataGen = WshServer.StreamCpuDataCommand(
{ id: model.blockId },
{ id: model.blockId, count: (block.meta?.count ?? 0) + 1 },
{ timeout: 999999999, noresponse: false }
);
try {

View File

@ -107,7 +107,7 @@ export class WaveAiModel implements ViewModel {
const viewTextChildren: HeaderElem[] = [
{
elemtype: "text",
text: get(atoms.settingsConfigAtom).ai?.model ?? "gpt-4o-mini",
text: get(atoms.settingsConfigAtom).ai?.model ?? "gpt-3.5-turbo",
},
];
return viewTextChildren;

View File

@ -134,6 +134,7 @@ declare global {
// wshrpc.CpuDataRequest
type CpuDataRequest = {
id: string;
count: number;
};
// wshrpc.CpuDataType
@ -217,6 +218,7 @@ declare global {
"term:fontfamily"?: string;
"term:mode"?: string;
"term:theme"?: string;
count?: number;
};
// tsgenmeta.MethodMeta

View File

@ -81,7 +81,7 @@ func GetWSEndpoint() string {
}
const DefaultMaxTokens = 1000
const DefaultModel = "gpt-4o-mini"
const DefaultModel = "gpt-3.5-turbo"
const DefaultStreamChanSize = 10
const PCloudWSEndpoint = "wss://wsapi.waveterm.dev/"
const PCloudWSEndpointVarName = "PCLOUD_WS_ENDPOINT"

View File

@ -259,7 +259,7 @@ func applyDefaultSettings(settings *SettingsConfigType) {
if settings.Ai == nil {
settings.Ai = &AiConfigType{
Name: userName,
Model: "gpt-4o-mini",
Model: "gpt-3.5-turbo",
MaxTokens: 1000,
TimeoutMs: 10 * 1000,
}

View File

@ -233,6 +233,7 @@ type OpenAIUsageType struct {
type CpuDataRequest struct {
Id string `json:"id"`
Count int `json:"count"`
}
type CpuDataType struct {

View File

@ -97,6 +97,17 @@ func (ws *WshServer) StreamCpuDataCommand(ctx context.Context, request wshrpc.Cp
rtn <- wshrpc.RespOrErrorUnion[wshrpc.CpuDataType]{Error: err}
return
}
blockData, getBlockDataErr := wstore.DBMustGet[*wstore.Block](ctx, request.Id)
if getBlockDataErr != nil {
rtn <- wshrpc.RespOrErrorUnion[wshrpc.CpuDataType]{Error: getBlockDataErr}
return
}
count := blockData.Meta.GetInt(wstore.MetaKey_Count, 0)
if count != request.Count {
rtn <- wshrpc.RespOrErrorUnion[wshrpc.CpuDataType]{Error: fmt.Errorf("new instance created. canceling old goroutine")}
return
}
}
}()

View File

@ -54,6 +54,7 @@ const (
MetaKey_TermFontFamily = "term:fontfamily"
MetaKey_TermMode = "term:mode"
MetaKey_TermTheme = "term:theme"
MetaKey_Count = "count" // temp for cpu plot. will remove later
)
// for typescript typing
@ -96,6 +97,7 @@ type MetaTSType struct {
TermFontFamily string `json:"term:fontfamily,omitempty"`
TermMode string `json:"term:mode,omitempty"`
TermTheme string `json:"term:theme,omitempty"`
Count int `json:"count,omitempty"` // temp for cpu plot. will remove later
}
type MetaDataDecl struct {