Spaces:
Build error
Build error
Update frontend/src/App.tsx
Browse files- frontend/src/App.tsx +26 -27
frontend/src/App.tsx
CHANGED
@@ -1,37 +1,36 @@
|
|
1 |
-
import { useEffect
|
2 |
-
|
3 |
-
import {
|
4 |
-
ChainlitAPI,
|
5 |
-
sessionState,
|
6 |
-
useChatSession,
|
7 |
-
} from "@chainlit/react-client";
|
8 |
import { Playground } from "./components/playground";
|
9 |
import { useRecoilValue } from "recoil";
|
10 |
|
11 |
-
|
|
|
|
|
|
|
12 |
const userEnv = {};
|
13 |
|
14 |
-
const apiClient = new ChainlitAPI(CHAINLIT_SERVER
|
|
|
15 |
|
16 |
function App() {
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
}, [connect]);
|
35 |
|
36 |
return (
|
37 |
<>
|
|
|
1 |
+
import { useEffect} from "react";
|
2 |
+
import { useState } from "react";
|
3 |
+
import { ChainlitAPI, sessionState, useChatSession } from "@chainlit/react-client";
|
|
|
|
|
|
|
|
|
4 |
import { Playground } from "./components/playground";
|
5 |
import { useRecoilValue } from "recoil";
|
6 |
|
7 |
+
|
8 |
+
const CHAINLIT_SERVER ="https://langroid-custom-front-end.hf.space";
|
9 |
+
|
10 |
+
|
11 |
const userEnv = {};
|
12 |
|
13 |
+
const apiClient = new ChainlitAPI(CHAINLIT_SERVER);
|
14 |
+
|
15 |
|
16 |
function App() {
|
17 |
+
const { connect } = useChatSession();
|
18 |
+
const session = useRecoilValue(sessionState);
|
19 |
+
|
20 |
+
useEffect(() => {
|
21 |
+
if (session?.socket.connected) {
|
22 |
+
return
|
23 |
+
}
|
24 |
+
fetch(apiClient
|
25 |
+
.buildEndpoint("/custom-auth")).then((res) => {
|
26 |
+
return res.json();
|
27 |
+
}
|
28 |
+
).then((data) => {
|
29 |
+
connect({ client: apiClient, userEnv, accessToken: `Bearer: ${data.token}` });
|
30 |
+
}
|
31 |
+
)
|
32 |
+
}, []);
|
33 |
+
|
|
|
34 |
|
35 |
return (
|
36 |
<>
|