lilt / lilt-python Goto Github PK
View Code? Open in Web Editor NEWAPI bindings for the Lilt REST API.
Home Page: https://lilt.github.io/lilt-python/
License: Other
API bindings for the Lilt REST API.
Home Page: https://lilt.github.io/lilt-python/
License: Other
We can publish the package as "lilt" since it hasn't yet been taken https://pypi.org/project/lilt/
The API client should be able to be generated via a command like this (see #6 for more info)
swagger-codegen generate -i ../front/doc/public-http-api-swagger.yaml -l python -DpackageName=pylilt -o .
Based on our call the other day we should rename this repo to "lilt-python". All generated API clients should use this naming convention ("lilt-node", "lilt-ruby", etc.).
since this is a public repo we could use github actions to run the tests
i also think we should use codecov to track test coverage and make sure we fill out all of the stubs generated by swagger-codegen.
Hi, was wondering what the licensing for this project is. It would be great to know what rights we have when it comes to this software, thanks
InlineResponse200
instead of File
in docs/FilesApi.mdI am trying to get started with lilt-python but I keep getting a 401 Unauthorized response. I've tried various permutations of lilt.Configuration and hit a wall. Here is my code.
from __future__ import print_function
import time
import lilt
from lilt.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to https://lilt.com/2
# See configuration.py for a list of all supported configuration parameters.
configuration = lilt.Configuration(host = "https://lilt.com/2",
api_key=<api key in quotes>,
username=<api key in quotes>,
password=<api key in quotes>)
# Just trying to get the list of supported languages
with lilt.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = lilt.LanguagesApi(api_client)
try:
# Retrieve supported languages
api_response = api_instance.get_languages()
pprint(api_response)
except ApiException as e:
print("Exception when calling LanguagesApi->get_languages: %s\n" % e)
Response:
Exception when calling LanguagesApi->get_languages: (401)
Reason: Unauthorized
Where am I going wrong?
currently swagger-codegen names the output package swagger_client
. there is some option in the cli somewhere to change this name. we should figure out what that option is so we can name the output package pylilt
I'm trying to pretranslate a list of raw strings. The easiest way to do this using the API seems to be uploading a document with pretranslation options enabled. Unfortunately it seems like submitting .txt files causes issues from the Python client.
My code below:
configuration = lilt.Configuration(
host = host,
api_key = {
'key': api_key
},
)
with lilt.ApiClient(configuration) as api_client:
api_instance = lilt.DocumentsApi(api_client)
name = 'dummy.txt'
project_id = 4
s = BytesIO("Hello, world!".encode())
body = s.read() .
pretranslate = 'tm+mt'
try:
api_response = api_instance.upload_document(name, project_id, body, pretranslate=pretranslate)
pprint(api_response)
except ApiException as e:
print("Exception when calling TranslateApi->translate_segment: %s\n" % e)
The corresponding uploaded document in UI:
Perhaps I'm misunderstanding the API as I see the same behavior with cURL:
curl -k -X POST "$host/documents/files?key=$key" \
--header "LILT-API: {\"name\": \"test2.txt\",\"pretranslate\": \"tm+mt\",\"project_id\": 4}" \
--header "Content-Type: application/octet-stream" \
--data-binary @test.txt
we should automate the workflow for publishing to pypi
this includes
for item 1 we can add a version number input to the workflow_dispatch
inputs so we can regenerate everything with the new version manually.
Add support for headers that are shown in POST /documents/files, rather than having everything inside the lilt-api
header
Possibly use https://generator.swagger.io/ since our docs are in swagger.
It seems that the LILT-API
header is not used. Instead individual values, such as project_id
are sent in their own headers.
The only references to LILT-API
appear to be in the commentary / documentation. A search confirms this: https://github.com/lilt/lilt-python/search?q=LILT-API
I have traced the headers including project_id
through to the urllib3.request()
method, and they are not passed as a JSON object with the header field LILT-API
.
Consequently, a call to the upload_document endpoint results in a bad request HTTP response body: {"message":"Invalid request: missing project_id header"}
Since we are planning on renaming the repo to "lilt-python" I think we should also change the package name. I think the package name should just be lilt
. The name is available on pypi so I think we should use that.
That means we should be able to install the package like this
pip install lilt
and import it like this
import lilt
We can just re-run the swagger-codegen command like this
swagger-codegen generate \
-i ../front/doc/public-http-api-swagger.yaml \
-l python \
-DpackageName=lilt \
--git-user-id lilt \
--git-repo-id lilt-python \
-o .
When downloading a pre-translated document using is_xliff="false"
the download_document attempts to decode the api response as UTF-8, which results in a UnicodeDecodeError.
To reproduce, upload a docx file for pretranslation. Once processed, download:
api_instance.download_document(job_id, is_xliff="false")
Observe the following error:
File "/path/to/src/lilt-pipeline-wrapper/venv/lib/python3.7/site-packages/lilt/api_client.py", line 205, in __call_api
response_data.data = response_data.data.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xce in position 10: invalid continuation byte
I found mention of a bytes
response type at
lilt-python/lilt/api_client.py
Line 200 in 364b633
Update swagger code gen
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.