@@ -69,11 +69,34 @@ def _call(
69
69
else :
70
70
logger .warning ('No user ID provided for Nextcloud TextToText provider' )
71
71
72
- response = nc .ocs (
73
- 'POST' ,
74
- '/ocs/v1.php/taskprocessing/schedule' ,
75
- json = {'type' : 'core:text2text' , 'appId' : 'context_chat_backend' , 'input' : {'input' : prompt }},
76
- )
72
+ sched_tries = 3
73
+ while True :
74
+ try :
75
+ sched_tries -= 1
76
+ if sched_tries <= 0 :
77
+ raise LlmException ('Failed to schedule Nextcloud TaskProcessing task, tried 3 times' )
78
+
79
+ response = nc .ocs (
80
+ 'POST' ,
81
+ '/ocs/v1.php/taskprocessing/schedule' ,
82
+ json = {'type' : 'core:text2text' , 'appId' : 'context_chat_backend' , 'input' : {'input' : prompt }},
83
+ )
84
+ break
85
+ except NextcloudException as e :
86
+ if e .status_code == httpx .codes .PRECONDITION_FAILED :
87
+ raise LlmException (
88
+ 'Failed to schedule Nextcloud TaskProcessing task: '
89
+ 'This app is setup to use a text generation provider in Nextcloud. '
90
+ 'No such provider is installed on Nextcloud instance. '
91
+ 'Please install integration_openai, llm2 or any other text2text provider.'
92
+ ) from e
93
+
94
+ if e .status_code == httpx .codes .TOO_MANY_REQUESTS :
95
+ logger .warning ('Rate limited during task scheduling, waiting 10s before retrying' )
96
+ time .sleep (10 )
97
+ continue
98
+
99
+ raise LlmException ('Failed to schedule Nextcloud TaskProcessing task' ) from e
77
100
78
101
try :
79
102
task = Response .model_validate (response ).task
@@ -103,8 +126,8 @@ def _call(
103
126
i += 1
104
127
continue
105
128
except NextcloudException as e :
106
- if e .status_code == 429 :
107
- logger .warning ('Rate limited during task polling, waiting 10s more ' )
129
+ if e .status_code == httpx . codes . TOO_MANY_REQUESTS :
130
+ logger .warning ('Rate limited during task polling, waiting 10s before retrying ' )
108
131
time .sleep (10 )
109
132
i += 2
110
133
continue
0 commit comments