feat(chat): prevent ws not open errors
This commit is contained in:
parent
7532c436db
commit
3a01eebc04
6 changed files with 59 additions and 15 deletions
|
@ -167,7 +167,6 @@ const createBasicAcademicSearchAnsweringChain = (
|
|||
if (optimizationMode === 'speed') {
|
||||
return docsWithContent.slice(0, 15);
|
||||
} else if (optimizationMode === 'balanced') {
|
||||
console.log('Balanced mode');
|
||||
const [docEmbeddings, queryEmbedding] = await Promise.all([
|
||||
embeddings.embedDocuments(
|
||||
docsWithContent.map((doc) => doc.pageContent),
|
||||
|
|
|
@ -227,7 +227,7 @@ const createBasicWebSearchRetrieverChain = (llm: BaseChatModel) => {
|
|||
The text will be shared inside the \`text\` XML tag, and the query inside the \`query\` XML tag.
|
||||
|
||||
<example>
|
||||
<text>
|
||||
1. \`<text>
|
||||
Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers.
|
||||
It was first released in 2013 and is developed by Docker, Inc. Docker is designed to make it easier to create, deploy, and run applications
|
||||
by using containers.
|
||||
|
@ -241,6 +241,26 @@ const createBasicWebSearchRetrieverChain = (llm: BaseChatModel) => {
|
|||
Docker is a revolutionary platform-as-a-service product developed by Docker, Inc., that uses container technology to make application
|
||||
deployment more efficient. It allows developers to package their software with all necessary dependencies, making it easier to run in
|
||||
any environment. Released in 2013, Docker has transformed the way applications are built, deployed, and managed.
|
||||
\`
|
||||
2. \`<text>
|
||||
The theory of relativity, or simply relativity, encompasses two interrelated theories of Albert Einstein: special relativity and general
|
||||
relativity. However, the word "relativity" is sometimes used in reference to Galilean invariance. The term "theory of relativity" was based
|
||||
on the expression "relative theory" used by Max Planck in 1906. The theory of relativity usually encompasses two interrelated theories by
|
||||
Albert Einstein: special relativity and general relativity. Special relativity applies to all physical phenomena in the absence of gravity.
|
||||
General relativity explains the law of gravitation and its relation to other forces of nature. It applies to the cosmological and astrophysical
|
||||
realm, including astronomy.
|
||||
</text>
|
||||
|
||||
<query>
|
||||
summarize
|
||||
</query>
|
||||
|
||||
Response:
|
||||
The theory of relativity, developed by Albert Einstein, encompasses two main theories: special relativity and general relativity. Special
|
||||
relativity applies to all physical phenomena in the absence of gravity, while general relativity explains the law of gravitation and its
|
||||
relation to other forces of nature. The theory of relativity is based on the concept of "relative theory," as introduced by Max Planck in
|
||||
1906. It is a fundamental theory in physics that has revolutionized our understanding of the universe.
|
||||
\`
|
||||
</example>
|
||||
|
||||
Everything below is the actual data you will be working with. Good luck!
|
||||
|
|
|
@ -78,6 +78,18 @@ export const handleConnection = async (
|
|||
ws.close();
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
if (ws.readyState === ws.OPEN) {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: 'signal',
|
||||
data: 'open',
|
||||
}),
|
||||
);
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, 5);
|
||||
|
||||
ws.on(
|
||||
'message',
|
||||
async (message) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue