muryshev commited on
Commit
18cee9d
·
1 Parent(s): 7a70cde

added wake up request

Browse files
chat-ui/src/lib/server/websearch/parseNalogGovRu.ts CHANGED
@@ -20,16 +20,20 @@ export async function parseNalogGovRu(url: string) {
20
 
21
  const { document } = dom.window;
22
  const textElTags = "h1, .wrap-content p";
23
- const paragraphs = document.querySelectorAll(textElTags);
24
  if (!paragraphs.length) {
25
- throw new Error(`Произошла ошибка при обработке страницы. Возможно, на сайте включена защита от ботов.`);
 
 
 
 
26
  }
27
  const paragraphTexts = Array.from(paragraphs).map((p) => p.textContent);
28
 
29
  // combine text contents from paragraphs and then remove newlines and multiple spaces
30
  const text = paragraphTexts.filter(t => t !== "")
31
- .map(t => !t?.endsWith('.') ? t+'.' : t)
32
- .join(" ")
33
- .replace(/ {2}|\r\n|\n|\r/gm, "");
34
  return text;
35
  }
 
20
 
21
  const { document } = dom.window;
22
  const textElTags = "h1, .wrap-content p";
23
+ let paragraphs = document.querySelectorAll(textElTags);
24
  if (!paragraphs.length) {
25
+ const fallbackElTags = "p";
26
+ paragraphs = document.querySelectorAll(fallbackElTags);
27
+ if (!paragraphs.length) {
28
+ throw new Error(`Произошла ошибка при обработке страницы. Возможно, на сайте включена защита от ботов.`);
29
+ }
30
  }
31
  const paragraphTexts = Array.from(paragraphs).map((p) => p.textContent);
32
 
33
  // combine text contents from paragraphs and then remove newlines and multiple spaces
34
  const text = paragraphTexts.filter(t => t !== "")
35
+ .map(t => !t?.endsWith('.') ? t + '.' : t)
36
+ .join(" ")
37
+ .replace(/ {2}|\r\n|\n|\r/gm, "");
38
  return text;
39
  }
chat-ui/src/lib/server/websearch/runWebSearch.ts CHANGED
@@ -109,7 +109,6 @@ export async function runWebSearch(
109
 
110
  if(texts && text.length > 0){
111
  appendUpdate("Получение релевантной информации");
112
- console.log('raw texts:', texts);
113
 
114
  const indices = await findSimilarSentences(prompt, texts.map((t) => t.text));//, { topK: topKClosestParagraphs});
115
  console.log('similarity check result:', indices);
 
109
 
110
  if(texts && text.length > 0){
111
  appendUpdate("Получение релевантной информации");
 
112
 
113
  const indices = await findSimilarSentences(prompt, texts.map((t) => t.text));//, { topK: topKClosestParagraphs});
114
  console.log('similarity check result:', indices);
chat-ui/src/routes/conversation/[id]/+server.ts CHANGED
@@ -127,6 +127,17 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
127
  const stream = new ReadableStream({
128
  async start(controller) {
129
  console.log('conversation start')
 
 
 
 
 
 
 
 
 
 
 
130
  const updates: MessageUpdate[] = [];
131
 
132
  function update(newUpdate: MessageUpdate) {
@@ -145,8 +156,6 @@ export async function POST({ request, fetch, locals, params, getClientAddress })
145
  }
146
 
147
 
148
- // fetch the endpoint
149
- const randomEndpoint = modelEndpoint(model);
150
  let usedFetch = fetch;
151
 
152
  async function saveLast(generated_text: string) {
 
127
  const stream = new ReadableStream({
128
  async start(controller) {
129
  console.log('conversation start')
130
+ // fetch the endpoint
131
+ const randomEndpoint = modelEndpoint(model);
132
+
133
+ // waking up instance
134
+ fetch(randomEndpoint.url, {
135
+ method: 'GET',
136
+ headers: {
137
+ 'Content-Type': 'application/json',
138
+ }
139
+ });
140
+
141
  const updates: MessageUpdate[] = [];
142
 
143
  function update(newUpdate: MessageUpdate) {
 
156
  }
157
 
158
 
 
 
159
  let usedFetch = fetch;
160
 
161
  async function saveLast(generated_text: string) {