Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit aee4484

Browse files
Upgrade version and add support for the new AI endpoints
Upgrade version to 0.4.0 and have support for text generation, sentiment and summarization endpoints
1 parent 322ed6a commit aee4484

File tree

4 files changed

+462
-1
lines changed

4 files changed

+462
-1
lines changed

openrobot/api_wrapper/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
from . import _async, _sync, translate, results, error, speech
99

10-
__version__ = '0.3.0.6'
10+
__version__ = '0.4.0'

openrobot/api_wrapper/_async.py

+176
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,182 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
185185

186186
# Methods to query to API:
187187

188+
async def text_generation(self, text: str, *, max_length: typing.Optional[int] = None, num_return: typing.Optional[int] = 1) -> TextGenerationResult:
189+
"""|coro|
190+
191+
Text Generation/Completion. This uses the /api/text-generation endpoint.
192+
193+
Parameters
194+
----------
195+
text: :class:`str`
196+
The text to be completed/generated.
197+
max_length: Optional[:class:`int`]
198+
The maximum length of the generated text. Defaults to ``None``.
199+
num_return: Optional[:class:`int`]
200+
The number of generated texts to return. Defaults to 1.
201+
202+
Raises
203+
------
204+
:exc:`Forbidden`
205+
API Returned a 403 HTTP Status Code.
206+
:exc:`BadRequest`
207+
API Returned a 400 HTTP Status Code.
208+
:exc:`InternalServerError`
209+
API Returned a 500 HTTP Status Code.
210+
211+
Returns
212+
-------
213+
:class:`TextGenerationResult`
214+
The text generation result returned by the API.
215+
"""
216+
217+
js = await self._request('POST', '/api/text-generation', data={'text': text, 'max_length': max_length, 'num_return': num_return})
218+
return TextGenerationResult(js)
219+
220+
async def text_generation_get(self, task_id: str) -> TextGenerationResult:
221+
"""|coro|
222+
223+
Gets the status of a text generation task. This uses the /api/text-generation/{task_id} endpoint.
224+
225+
Parameters
226+
----------
227+
task_id: :class:`str`
228+
The task ID of the text generation task.
229+
230+
Raises
231+
------
232+
:exc:`Forbidden`
233+
API Returned a 403 HTTP Status Code.
234+
:exc:`BadRequest`
235+
API Returned a 400 HTTP Status Code.
236+
:exc:`InternalServerError`
237+
API Returned a 500 HTTP Status Code.
238+
239+
Returns
240+
-------
241+
:class:`TextGenerationResult`
242+
The text generation result returned by the API.
243+
"""
244+
245+
js = await self._request('GET', f'/api/text-generation/{quote(task_id)}')
246+
return TextGenerationResult(js)
247+
248+
async def sentiment(self, text: str) -> SentimentResult:
249+
"""|coro|
250+
251+
Performs a Sentiment check on a text.
252+
253+
Parameters
254+
----------
255+
text: :class:`str`
256+
The text to be checked.
257+
258+
Raises
259+
------
260+
:exc:`Forbidden`
261+
API Returned a 403 HTTP Status Code.
262+
:exc:`BadRequest`
263+
API Returned a 400 HTTP Status Code.
264+
:exc:`InternalServerError`
265+
API Returned a 500 HTTP Status Code.
266+
267+
Returns
268+
-------
269+
:class:`SentimentResult`
270+
The sentiment result returned by the API.
271+
"""
272+
273+
js = await self._request('POST', '/api/sentiment', data={'text': text})
274+
return SentimentResult(js)
275+
276+
async def sentiment_get(self, task_id: str) -> SentimentResult:
277+
"""|coro|
278+
279+
Gets the status of a sentiment task. This uses the /api/sentiment/{task_id} endpoint.
280+
281+
Parameters
282+
----------
283+
task_id: :class:`str`
284+
The task ID of the sentiment task.
285+
286+
Raises
287+
------
288+
:exc:`Forbidden`
289+
API Returned a 403 HTTP Status Code.
290+
:exc:`BadRequest`
291+
API Returned a 400 HTTP Status Code.
292+
:exc:`InternalServerError`
293+
API Returned a 500 HTTP Status Code.
294+
295+
Returns
296+
-------
297+
:class:`SentimentResult`
298+
The sentiment result returned by the API.
299+
"""
300+
301+
js = await self._request('GET', f'/api/sentiment/{quote(task_id)}')
302+
return SentimentResult(js)
303+
304+
async def summarization(self, text: str, *, max_length: typing.Optional[int] = None, min_length: typing.Optional[int] = 1) -> SummarizationResult:
305+
"""|coro|
306+
307+
Summarizes a text. This uses the /api/summarization endpoint.
308+
309+
Parameters
310+
----------
311+
text: :class:`str`
312+
The text to be summarized.
313+
max_length: Optional[:class:`int`]
314+
The maximum length of the summary. Defaults to ``None``.
315+
min_length: Optional[:class:`int`]
316+
The minimum length of the summary. Defaults to ``None``.
317+
318+
Raises
319+
------
320+
:exc:`Forbidden`
321+
API Returned a 403 HTTP Status Code.
322+
:exc:`BadRequest`
323+
API Returned a 400 HTTP Status Code.
324+
:exc:`InternalServerError`
325+
API Returned a 500 HTTP Status Code.
326+
327+
Returns
328+
-------
329+
:class:`SummarizationResult`
330+
The summarization result returned by the API.
331+
"""
332+
333+
js = await self._request('POST', '/api/summarization', data={'text': text, 'max_length': max_length, 'min_length': min_length})
334+
return SummarizationResult(js)
335+
336+
async def summarization_get(self, task_id: str) -> SummarizationResult:
337+
"""|coro|
338+
339+
Gets the status of a summarization task. This uses the /api/summarization/{task_id} endpoint.
340+
341+
Parameters
342+
----------
343+
task_id: :class:`str`
344+
The task ID of the summarization task.
345+
346+
Raises
347+
------
348+
:exc:`Forbidden`
349+
API Returned a 403 HTTP Status Code.
350+
:exc:`BadRequest`
351+
API Returned a 400 HTTP Status Code.
352+
:exc:`InternalServerError`
353+
API Returned a 500 HTTP Status Code.
354+
355+
Returns
356+
-------
357+
:class:`SummarizationResult`
358+
The summarization result returned by the API.
359+
"""
360+
361+
js = await self._request('GET', f'/api/summarization/{quote(task_id)}')
362+
return SummarizationResult(js)
363+
188364
async def lyrics(self, query: str) -> LyricResult:
189365
"""|coro|
190366

openrobot/api_wrapper/_sync.py

+170
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,176 @@ def _request(self, method: str, url: str, **kwargs):
136136

137137
# Methods to query to API:
138138

139+
def text_generation(self, text: str, *, max_length: typing.Optional[int] = None, num_return: typing.Optional[int] = 1) -> TextGenerationResult:
140+
"""
141+
Text Generation/Completion. This uses the /api/text-generation endpoint.
142+
143+
Parameters
144+
----------
145+
text: :class:`str`
146+
The text to be completed/generated.
147+
max_length: Optional[:class:`int`]
148+
The maximum length of the generated text. Defaults to ``None``.
149+
num_return: Optional[:class:`int`]
150+
The number of generated texts to return. Defaults to 1.
151+
152+
Raises
153+
------
154+
:exc:`Forbidden`
155+
API Returned a 403 HTTP Status Code.
156+
:exc:`BadRequest`
157+
API Returned a 400 HTTP Status Code.
158+
:exc:`InternalServerError`
159+
API Returned a 500 HTTP Status Code.
160+
161+
Returns
162+
-------
163+
:class:`TextGenerationResult`
164+
The text generation result returned by the API.
165+
"""
166+
167+
js = self._request('POST', '/api/text-generation', data={'text': text, 'max_length': max_length, 'num_return': num_return})
168+
return TextGenerationResult(js)
169+
170+
def text_generation_get(self, task_id: str) -> TextGenerationResult:
171+
"""
172+
Gets the status of a text generation task. This uses the /api/text-generation/{task_id} endpoint.
173+
174+
Parameters
175+
----------
176+
task_id: :class:`str`
177+
The task ID of the text generation task.
178+
179+
Raises
180+
------
181+
:exc:`Forbidden`
182+
API Returned a 403 HTTP Status Code.
183+
:exc:`BadRequest`
184+
API Returned a 400 HTTP Status Code.
185+
:exc:`InternalServerError`
186+
API Returned a 500 HTTP Status Code.
187+
188+
Returns
189+
-------
190+
:class:`TextGenerationResult`
191+
The text generation result returned by the API.
192+
"""
193+
194+
js = self._request('GET', f'/api/text-generation/{quote(task_id)}')
195+
return TextGenerationResult(js)
196+
197+
def sentiment(self, text: str) -> SentimentResult:
198+
"""
199+
Performs a Sentiment check on a text.
200+
201+
Parameters
202+
----------
203+
text: :class:`str`
204+
The text to be checked.
205+
206+
Raises
207+
------
208+
:exc:`Forbidden`
209+
API Returned a 403 HTTP Status Code.
210+
:exc:`BadRequest`
211+
API Returned a 400 HTTP Status Code.
212+
:exc:`InternalServerError`
213+
API Returned a 500 HTTP Status Code.
214+
215+
Returns
216+
-------
217+
:class:`SentimentResult`
218+
The sentiment result returned by the API.
219+
"""
220+
221+
js = self._request('POST', '/api/sentiment', data={'text': text})
222+
return SentimentResult(js)
223+
224+
def sentiment_get(self, task_id: str) -> SentimentResult:
225+
"""
226+
Gets the status of a sentiment task. This uses the /api/sentiment/{task_id} endpoint.
227+
228+
Parameters
229+
----------
230+
task_id: :class:`str`
231+
The task ID of the sentiment task.
232+
233+
Raises
234+
------
235+
:exc:`Forbidden`
236+
API Returned a 403 HTTP Status Code.
237+
:exc:`BadRequest`
238+
API Returned a 400 HTTP Status Code.
239+
:exc:`InternalServerError`
240+
API Returned a 500 HTTP Status Code.
241+
242+
Returns
243+
-------
244+
:class:`SentimentResult`
245+
The sentiment result returned by the API.
246+
"""
247+
248+
js = self._request('GET', f'/api/sentiment/{quote(task_id)}')
249+
return SentimentResult(js)
250+
251+
def summarization(self, text: str, *, max_length: typing.Optional[int] = None, min_length: typing.Optional[int] = 1) -> SummarizationResult:
252+
"""
253+
Summarizes a text. This uses the /api/summarization endpoint.
254+
255+
Parameters
256+
----------
257+
text: :class:`str`
258+
The text to be summarized.
259+
max_length: Optional[:class:`int`]
260+
The maximum length of the summary. Defaults to ``None``.
261+
min_length: Optional[:class:`int`]
262+
The minimum length of the summary. Defaults to ``None``.
263+
264+
Raises
265+
------
266+
:exc:`Forbidden`
267+
API Returned a 403 HTTP Status Code.
268+
:exc:`BadRequest`
269+
API Returned a 400 HTTP Status Code.
270+
:exc:`InternalServerError`
271+
API Returned a 500 HTTP Status Code.
272+
273+
Returns
274+
-------
275+
:class:`SummarizationResult`
276+
The summarization result returned by the API.
277+
"""
278+
279+
js = self._request('POST', '/api/summarization', data={'text': text, 'max_length': max_length, 'min_length': min_length})
280+
return SummarizationResult(js)
281+
282+
def summarization_get(self, task_id: str) -> SummarizationResult:
283+
"""
284+
Gets the status of a summarization task. This uses the /api/summarization/{task_id} endpoint.
285+
286+
Parameters
287+
----------
288+
task_id: :class:`str`
289+
The task ID of the summarization task.
290+
291+
Raises
292+
------
293+
:exc:`Forbidden`
294+
API Returned a 403 HTTP Status Code.
295+
:exc:`BadRequest`
296+
API Returned a 400 HTTP Status Code.
297+
:exc:`InternalServerError`
298+
API Returned a 500 HTTP Status Code.
299+
300+
Returns
301+
-------
302+
:class:`SummarizationResult`
303+
The summarization result returned by the API.
304+
"""
305+
306+
js = self._request('GET', f'/api/summarization/{quote(task_id)}')
307+
return SummarizationResult(js)
308+
139309
def lyrics(self, query: str) -> LyricResult:
140310
"""
141311
Gets the lyrics from the API.

0 commit comments

Comments
 (0)