Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions context_chat_backend/dyn_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def load(self):
)
pid.value = proc.pid

last_resp, last_exc = None, None
# poll for heartbeat
try_ = 0
while try_ < 20:
Expand All @@ -84,12 +85,17 @@ def load(self):
)
if response.status_code == 200:
return
except Exception:
last_resp = response
except Exception as e:
last_exc = e
logger.debug(f'Try {try_} failed in exception')
try_ += 1
sleep(3)

raise EmbeddingException('Error: the embedding server is not responding')
raise EmbeddingException(
'Error: the embedding server is not responding or could not be started. '
+ (f'\nLast error: {last_resp.status_code} {last_resp.text}' if last_resp else '')
) from last_exc

def offload(self):
global pid
Expand Down
37 changes: 30 additions & 7 deletions context_chat_backend/models/nc_texttotext.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,34 @@ def _call(
else:
logger.warning('No user ID provided for Nextcloud TextToText provider')

response = nc.ocs(
'POST',
'/ocs/v1.php/taskprocessing/schedule',
json={'type': 'core:text2text', 'appId': 'context_chat_backend', 'input': {'input': prompt}},
)
sched_tries = 3
while True:
try:
sched_tries -= 1
if sched_tries <= 0:
raise LlmException('Failed to schedule Nextcloud TaskProcessing task, tried 3 times')

response = nc.ocs(
'POST',
'/ocs/v1.php/taskprocessing/schedule',
json={'type': 'core:text2text', 'appId': 'context_chat_backend', 'input': {'input': prompt}},
)
break
except NextcloudException as e:
if e.status_code == httpx.codes.PRECONDITION_FAILED:
raise LlmException(
'Failed to schedule Nextcloud TaskProcessing task: '
'This app is setup to use a text generation provider in Nextcloud. '
'No such provider is installed on Nextcloud instance. '
'Please install integration_openai, llm2 or any other text2text provider.'
) from e

if e.status_code == httpx.codes.TOO_MANY_REQUESTS:
logger.warning('Rate limited during task scheduling, waiting 10s before retrying')
time.sleep(10)
continue

raise LlmException('Failed to schedule Nextcloud TaskProcessing task') from e

try:
task = Response.model_validate(response).task
Expand Down Expand Up @@ -103,8 +126,8 @@ def _call(
i += 1
continue
except NextcloudException as e:
if e.status_code == 429:
logger.warning('Rate limited during task polling, waiting 10s more')
if e.status_code == httpx.codes.TOO_MANY_REQUESTS:
logger.warning('Rate limited during task polling, waiting 10s before retrying')
time.sleep(10)
i += 2
continue
Expand Down
Loading