Skip to content

Commit 4e4f23d

Browse files
author
jabrock
committed
updating conversationId and other cleanup
1 parent bb8237c commit 4e4f23d

File tree

5 files changed

+52
-33
lines changed

5 files changed

+52
-33
lines changed

app/src/components/app.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { Header } from "./header";
22
import Content from "./content/index";
33
import { registerCustomElement } from "ojs/ojvcomponent";
4-
import "preact";
4+
import { createContext } from "preact";
55

66
type Props = {
77
appName: string;
88
};
9+
const convoUUID = window.crypto.randomUUID();
10+
export const ConvoCtx = createContext(convoUUID);
911

1012
export const App = registerCustomElement("app-root", (props: Props) => {
1113
props.appName = "Generative AI JET UI";
1214

1315
return (
1416
<div id="appContainer" class="oj-web-applayout-page">
15-
<Header appName={props.appName} />
16-
<Content />
17+
<ConvoCtx.Provider value={convoUUID}>
18+
{console.log("UUID: ", convoUUID)}
19+
<Header appName={props.appName} />
20+
<Content />
21+
</ConvoCtx.Provider>
1722
</div>
1823
);
1924
});

app/src/components/content/index.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import "oj-c/drawer-popup";
99
import MutableArrayDataProvider = require("ojs/ojmutablearraydataprovider");
1010
import { MessageToastItem } from "oj-c/message-toast";
1111
import { InputSearchElement } from "ojs/ojinputsearch";
12-
import { useState, useEffect, useRef } from "preact/hooks";
12+
import { useState, useEffect, useRef, useContext } from "preact/hooks";
1313
import * as Questions from "text!./data/questions.json";
1414
import * as Answers from "text!./data/answers.json";
1515
import { initWebSocket } from "./websocket-interface";
1616
import { InitStomp, sendPrompt } from "./stomp-interface";
1717
import { Client } from "@stomp/stompjs";
18+
import { ConvoCtx } from "../app";
1819

1920
type ServiceTypes = "text" | "summary" | "sim";
2021
type BackendTypes = "java" | "python";
@@ -26,12 +27,14 @@ type Chat = {
2627
};
2728

2829
const defaultServiceType: string = localStorage.getItem("service") || "text";
29-
const defaultBackendType: String = localStorage.getItem("backend") || "java";
30+
const defaultBackendType: string = localStorage.getItem("backend") || "java";
3031

3132
const Content = () => {
33+
const conversationId = useContext(ConvoCtx);
3234
const [update, setUpdate] = useState<Array<object>>([]);
3335
const [busy, setBusy] = useState<boolean>(false);
3436
const [summaryResults, setSummaryResults] = useState<string>("");
37+
const [modelId, setModelId] = useState<string | null>(null);
3538
const [summaryPrompt, setSummaryPrompt] = useState<string>();
3639
const [serviceType, setServiceType] = useState<ServiceTypes>(
3740
defaultServiceType as ServiceTypes
@@ -76,6 +79,7 @@ const Content = () => {
7679
await sleep(2000);
7780
}
7881
};
82+
7983
useEffect(() => {
8084
switch (serviceType) {
8185
case "text":
@@ -158,16 +162,13 @@ const Content = () => {
158162
setUpdate(chatData.current);
159163
setBusy(true);
160164

161-
// simulating the delay for now just to show what the animation looks like.
162-
setTimeout(() => {
163-
if (backendType === "python") {
164-
socket.current?.send(
165-
JSON.stringify({ msgType: "question", data: question.current })
166-
);
167-
} else {
168-
sendPrompt(client, question.current!);
169-
}
170-
}, 300);
165+
if (backendType === "python") {
166+
socket.current?.send(
167+
JSON.stringify({ msgType: "question", data: question.current })
168+
);
169+
} else {
170+
sendPrompt(client, question.current!, modelId!, conversationId!);
171+
}
171172
}
172173
};
173174

@@ -198,7 +199,10 @@ const Content = () => {
198199
localStorage.setItem("backend", backend);
199200
location.reload();
200201
};
201-
202+
const modelIdChangeHandler = (event: CustomEvent) => {
203+
console.log("model Id: ", event.detail.value);
204+
if (event.detail.value != null) setModelId(event.detail.value);
205+
};
202206
const clearSummary = () => {
203207
setSummaryResults("");
204208
};
@@ -223,6 +227,7 @@ const Content = () => {
223227
backendType={backendType}
224228
aiServiceChange={serviceTypeChangeHandler}
225229
backendChange={backendTypeChangeHandler}
230+
modelIdChange={modelIdChangeHandler}
226231
/>
227232
</oj-c-drawer-popup>
228233
<div class="oj-flex-bar oj-flex-item demo-header oj-sm-12">

app/src/components/content/settings.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "preact";
1+
import { ComponentProps } from "preact";
22
import { useEffect, useRef } from "preact/hooks";
33
import "oj-c/radioset";
44
import "oj-c/form-layout";
@@ -17,13 +17,14 @@ type Props = {
1717
backendType: BackendTypeVal;
1818
aiServiceChange: (service: ServiceTypeVal) => void;
1919
backendChange: (backend: BackendTypeVal) => void;
20+
modelIdChange: (modelName: any) => void;
2021
};
2122

2223
const serviceTypes = [
2324
{ value: "text", label: "Generative Text" },
2425
{ value: "summary", label: "Summarize" },
25-
{ value: "sim", label: "Simulation" },
2626
];
27+
// { value: "sim", label: "Simulation" },
2728

2829
const backendTypes = [
2930
{ value: "java", label: "Java" },
@@ -93,14 +94,15 @@ export const Settings = (props: Props) => {
9394
onvalueChanged={handleBackendTypeChange}
9495
></oj-c-radioset>
9596
</oj-c-form-layout>
96-
{props.aiServiceType == "summary" && props.backendType == "java" && (
97+
{props.aiServiceType == "text" && props.backendType == "java" && (
9798
<>
9899
<h2 class="oj-typography-heading-sm">Model options</h2>
99100
<oj-c-form-layout>
100101
<oj-c-select-single
101102
data={modelDP.current}
102103
labelHint={"Model"}
103104
itemText={"name"}
105+
onvalueChanged={props.modelIdChange}
104106
></oj-c-select-single>
105107
</oj-c-form-layout>
106108
</>

app/src/components/content/stomp-interface.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,20 @@ export const InitStomp = (
6565
return client;
6666
};
6767

68-
export const sendPrompt = (client: Client | null, prompt: string) => {
68+
export const sendPrompt = (
69+
client: Client | null,
70+
prompt: string,
71+
modelId: string,
72+
convoId: string
73+
) => {
6974
if (client?.connected) {
7075
console.log("Sending prompt: ", prompt);
7176
client.publish({
7277
destination: "/genai/prompt",
7378
body: JSON.stringify({
74-
conversationId: "something",
75-
content: prompt, //"Show me code for a websocket service using JavaScript",
76-
modelId: "notapply",
79+
conversationId: convoId,
80+
content: prompt,
81+
modelId: modelId,
7782
}),
7883
});
7984
} else {

app/src/components/content/summary.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,18 @@ export const Summary = ({
282282
FILE_SIZE / 1000
283283
}KB per PDF file.`}
284284
></oj-c-file-picker>
285-
<oj-c-input-text
286-
id="promptInput"
287-
ref={promptInputRef}
288-
required
289-
aria-label="enter document summary prompt"
290-
class="oj-sm-width-full oj-md-width-1/2 oj-sm-margin-4x-top oj-sm-margin-4x-bottom"
291-
labelHint="Enter the document summary prompt"
292-
labelEdge="top"
293-
onvalueChanged={submitPrompt}
294-
></oj-c-input-text>
285+
{backendType === "python" && (
286+
<oj-c-input-text
287+
id="promptInput"
288+
ref={promptInputRef}
289+
required
290+
aria-label="enter document summary prompt"
291+
class="oj-sm-width-full oj-md-width-1/2 oj-sm-margin-4x-top oj-sm-margin-4x-bottom"
292+
labelHint="Enter the document summary prompt"
293+
labelEdge="top"
294+
onvalueChanged={submitPrompt}
295+
></oj-c-input-text>
296+
)}
295297
</oj-validation-group>
296298
{invalidFiles.current.length !== 1 && fileNames && (
297299
<>

0 commit comments

Comments
 (0)