Skip to content

Commit

Permalink
Merge pull request #1 from fengsh27/wip/fengsh/communicate-with-bioch…
Browse files Browse the repository at this point in the history
…atter

feat: Communicate with biochatter server
  • Loading branch information
fengsh27 authored Oct 17, 2023
2 parents 9835206 + 2682ba7 commit da0bcab
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ export class ChatGPTApi implements LLMApi {
presence_penalty: modelConfig.presence_penalty,
frequency_penalty: modelConfig.frequency_penalty,
top_p: modelConfig.top_p,
session_id: useChatStore.getState().currentSession().id,
};

console.log("[Request] openai payload: ", requestPayload);

const shouldStream = !!options.config.stream;
const shouldStream = false; // !!options.config.stream; //
const controller = new AbortController();
options.onController?.(controller);

Expand Down
39 changes: 39 additions & 0 deletions app/masks/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,43 @@ export const EN_MASKS: BuiltinMask[] = [
builtin: true,
createdAt: 1688899480413,
},
{
avatar: "1f977",
name: "Biomedical researcher assistant",
context: [
{
id: "biomedical-researcher-assistant-1",
role: "user",
content: "You are an assistant to a biomedical researcher.",
date: "",
},
{
id: "biomedical-researcher-assistant-2",
role: "user",
content:
"Your role is to contextualise the user's findings with biomedical background knowledge. If provided with a list, please give granular feedback about the individual entities, your knowledge about them, and what they may mean in the context of the research.",
date: "",
},
{
id: "biomedical-researcher-assistant-3",
role: "user",
content:
"You can ask the user to provide explanations and more background at any time, for instance on the treatment a patient has received, or the experimental background. But for now, wait for the user to ask a question.",
date: "",
},
],
modelConfig: {
model: "gpt-4",
temperature: 0.7,
max_tokens: 2000,
presence_penalty: 0,
frequency_penalty: 0,
sendMemory: true,
historyMessageCount: 4,
compressMessageLengthThreshold: 2000,
},
lang: "en",
builtin: true,
createdAt: 1697222692762,
},
];
2 changes: 1 addition & 1 deletion app/masks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export const BUILTIN_MASK_STORE = {
},
};

export const BUILTIN_MASKS: BuiltinMask[] = [...CN_MASKS, ...EN_MASKS].map(
export const BUILTIN_MASKS: BuiltinMask[] = [/*...CN_MASKS,*/ ...EN_MASKS].map(
(m) => BUILTIN_MASK_STORE.add(m),
);
10 changes: 6 additions & 4 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";

import { v4 as uuidv4 } from "uuid";
import { trimTopic } from "../utils";

import Locale, { getLang } from "../locales";
Expand All @@ -20,6 +20,8 @@ import { estimateTokenLength } from "../utils/token";
import { nanoid } from "nanoid";
import { createPersistStore } from "../utils/store";

const generateUniqId = () => uuidv4();

export type ChatMessage = RequestMessage & {
date: string;
streaming?: boolean;
Expand Down Expand Up @@ -66,7 +68,7 @@ export const BOT_HELLO: ChatMessage = createMessage({

function createEmptySession(): ChatSession {
return {
id: nanoid(),
id: generateUniqId(),
topic: DEFAULT_TOPIC,
memoryPrompt: "",
messages: [],
Expand Down Expand Up @@ -574,7 +576,7 @@ export const useChatStore = createPersistStore(
),
config: {
...modelConfig,
stream: true,
stream: false,
model: getSummarizeModel(session.mask.modelConfig.model),
},
onUpdate(message) {
Expand Down Expand Up @@ -640,7 +642,7 @@ export const useChatStore = createPersistStore(
if (version < 3) {
// migrate id to nanoid
newState.sessions.forEach((s) => {
s.id = nanoid();
s.id = generateUniqId();
s.messages.forEach((m) => (m.id = nanoid()));
});
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"sass": "^1.59.2",
"spark-md5": "^3.0.2",
"use-debounce": "^9.0.4",
"uuid": "^9.0.1",
"zustand": "^4.3.8"
},
"devDependencies": {
Expand All @@ -48,6 +49,7 @@
"@types/react-dom": "^18.2.7",
"@types/react-katex": "^3.0.0",
"@types/spark-md5": "^3.0.2",
"@types/uuid": "^9.0.5",
"cross-env": "^7.0.3",
"eslint": "^8.49.0",
"eslint-config-next": "13.4.19",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,11 @@
resolved "https://registry.npmmirror.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz#b6725d5f4af24ace33b36fafd295136e75509f43"
integrity sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==

"@types/uuid@^9.0.5":
version "9.0.5"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.5.tgz#25a71eb73eba95ac0e559ff3dd018fc08294acf6"
integrity sha512-xfHdwa1FMJ082prjSJpoEI57GZITiQz10r3vEJCHa2khEFQjKy91aWKz6+zybzssCvXUwE1LQWgWVwZ4nYUvHQ==

"@typescript-eslint/parser@^5.4.2 || ^6.0.0":
version "6.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.4.0.tgz#47e7c6e22ff1248e8675d95f488890484de67600"
Expand Down Expand Up @@ -5937,6 +5942,11 @@ uuid@^9.0.0:
resolved "https://registry.npmmirror.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==

uuid@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==

uvu@^0.5.0:
version "0.5.6"
resolved "https://registry.yarnpkg.com/uvu/-/uvu-0.5.6.tgz#2754ca20bcb0bb59b64e9985e84d2e81058502df"
Expand Down

0 comments on commit da0bcab

Please sign in to comment.