Spaces:
Sleeping
Sleeping
update
Browse files- components/llm/deepinfra_api.py +0 -1
- routes/llm.py +12 -1
components/llm/deepinfra_api.py
CHANGED
@@ -328,7 +328,6 @@ class DeepInfraApi(LlmApi):
|
|
328 |
Yields:
|
329 |
str: Токены ответа LLM.
|
330 |
"""
|
331 |
-
print(request.history)
|
332 |
timeout = httpx.Timeout(connect=30.0, read=None, pool=None, write=None, timeout=None)
|
333 |
attempt = 0
|
334 |
|
|
|
328 |
Yields:
|
329 |
str: Токены ответа LLM.
|
330 |
"""
|
|
|
331 |
timeout = httpx.Timeout(connect=30.0, read=None, pool=None, write=None, timeout=None)
|
332 |
attempt = 0
|
333 |
|
routes/llm.py
CHANGED
@@ -2,6 +2,7 @@ import json
|
|
2 |
import logging
|
3 |
import os
|
4 |
from typing import Annotated, AsyncGenerator, List, Optional
|
|
|
5 |
|
6 |
from fastapi import APIRouter, Depends, HTTPException
|
7 |
from fastapi.responses import StreamingResponse
|
@@ -124,6 +125,7 @@ def collapse_history_to_first_message(chat_request: ChatRequest) -> ChatRequest:
|
|
124 |
searchResults=''
|
125 |
)
|
126 |
return ChatRequest(history=[new_message])
|
|
|
127 |
|
128 |
async def sse_generator(request: ChatRequest, llm_api: DeepInfraApi, system_prompt: str,
|
129 |
predict_params: LlmPredictParams,
|
@@ -166,7 +168,16 @@ async def sse_generator(request: ChatRequest, llm_api: DeepInfraApi, system_prom
|
|
166 |
previous_entities, chunk_ids, scores = entity_service.search_similar(qe_result.search_query,
|
167 |
dataset.id, previous_entities)
|
168 |
text_chunks = entity_service.build_text(chunk_ids, scores)
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
all_entities = [chunk_ids] + previous_entities
|
171 |
|
172 |
search_results_event = {
|
|
|
2 |
import logging
|
3 |
import os
|
4 |
from typing import Annotated, AsyncGenerator, List, Optional
|
5 |
+
import asyncio
|
6 |
|
7 |
from fastapi import APIRouter, Depends, HTTPException
|
8 |
from fastapi.responses import StreamingResponse
|
|
|
125 |
searchResults=''
|
126 |
)
|
127 |
return ChatRequest(history=[new_message])
|
128 |
+
|
129 |
|
130 |
async def sse_generator(request: ChatRequest, llm_api: DeepInfraApi, system_prompt: str,
|
131 |
predict_params: LlmPredictParams,
|
|
|
168 |
previous_entities, chunk_ids, scores = entity_service.search_similar(qe_result.search_query,
|
169 |
dataset.id, previous_entities)
|
170 |
text_chunks = entity_service.build_text(chunk_ids, scores)
|
171 |
+
|
172 |
+
|
173 |
+
async def build_text_async(entities):
|
174 |
+
return await asyncio.to_thread(entity_service.build_text, entities)
|
175 |
+
|
176 |
+
# all_text_chunks = [text_chunks] + [entity_service.build_text(entities) for entities in previous_entities]
|
177 |
+
tasks = [build_text_async(entities) for entities in previous_entities]
|
178 |
+
built_texts = await asyncio.gather(*tasks)
|
179 |
+
|
180 |
+
all_text_chunks = [text_chunks] + built_texts
|
181 |
all_entities = [chunk_ids] + previous_entities
|
182 |
|
183 |
search_results_event = {
|