omnibot3000 1.8.2 → 1.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,8 @@
1
1
  import {memo, useEffect, useRef, useState} from "react";
2
2
  import {useNavigate} from "react-router-dom";
3
3
 
4
- import {ChatCompletionMessageParam} from "openai/resources";
5
- import {ChatCompletionChunk} from "openai/resources/index.mjs";
6
- import {Stream} from "openai/streaming.mjs";
7
-
8
- import getData, {getStartButton, getSystemConfig} from "@api/api";
4
+ import {getStartButton} from "@api/api";
5
+ import getStream from "@api/getStream";
9
6
  import OmnibotSpeak from "@commons/OmnibotSpeak";
10
7
  import Container from "@layout/Container";
11
8
  import Button from "@ui/Button";
@@ -31,40 +28,6 @@ const Home = () => {
31
28
  setStartButton(formatText(data));
32
29
  };
33
30
 
34
- const getResponse = async () => {
35
- try {
36
- const messages: ChatCompletionMessageParam[] = [getSystemConfig()];
37
-
38
- messages.push({
39
- role: "developer",
40
- content: `\
41
- write an intro message for the user. keep it short and to the point. \
42
- explain who are you, why you are here and how you can help the user. \
43
- separate each element with an empty line.`,
44
- });
45
-
46
- const response = (await getData(messages)) as Stream<ChatCompletionChunk>;
47
-
48
- for await (const chunk of response) {
49
- const choice = chunk.choices?.[0] || {};
50
- const finish_reason = choice.finish_reason;
51
- const text = choice.delta?.content || "";
52
- if (finish_reason) {
53
- setLoading(false);
54
- if (finish_reason === "length")
55
- setResponse((prev) => `${prev}\n\n[max tokens length reached]\n`);
56
- break;
57
- }
58
- if (!text) continue;
59
- setResponse((prev) => `${prev}${text}`);
60
- }
61
- } catch (error) {
62
- console.error("Error reading stream:", error);
63
- setLoading(false);
64
- setResponse("no signal");
65
- }
66
- };
67
-
68
31
  const newChat = () => {
69
32
  chatStore.setChatId();
70
33
  chatStore.setCompletionId();
@@ -78,7 +41,21 @@ separate each element with an empty line.`,
78
41
 
79
42
  chatStore.resetChat();
80
43
  setLoading(true);
81
- getResponse();
44
+ getStream(
45
+ setLoading,
46
+ setResponse,
47
+ [
48
+ "keep it short and straight to the point",
49
+ "do not repeat yourself",
50
+ "do not exceed 512 characters",
51
+ "separate each element with an empty line",
52
+ ],
53
+ [
54
+ "write an intro message for the user",
55
+ "explain who are you, why you are here and what you can do",
56
+ "it's not a help or documentation page",
57
+ ],
58
+ );
82
59
  updateStartButton();
83
60
  }, []);
84
61
 
@@ -10,8 +10,6 @@ import styles from "@help/Help.module.css";
10
10
 
11
11
  import cls from "classnames";
12
12
 
13
- console.info(JSON.stringify(import.meta.env, null, 2));
14
-
15
13
  const API_PORT = Number(import.meta.env.API_PORT) || 3001;
16
14
  const API_PATH = import.meta.env.API_PATH || "/api";
17
15
 
@@ -27,7 +25,7 @@ const Version = () => {
27
25
  const chatStore = useChatCompletionStore();
28
26
 
29
27
  const hasRunOnce = useRef(false);
30
- const [response, setResponse] = useState<string>("loading...");
28
+ const [response, setResponse] = useState<string>("");
31
29
  const [loading, setLoading] = useState<boolean>(false);
32
30
 
33
31
  const getResponse = async () => {
@@ -54,6 +52,10 @@ const Version = () => {
54
52
  setLoading(true);
55
53
  getResponse();
56
54
  displayPackageVersion();
55
+ console.info(
56
+ `%c${JSON.stringify(import.meta.env, null, 2)}`,
57
+ "color: #999",
58
+ );
57
59
  }, []);
58
60
 
59
61
  return (