Package: oxapi
This Python library provides simplified access to the OxAPI from applications written in Python.importoxapioxapi.api_key="sk-..."encoding=oxapi.Encoding.run(model="all-mpnet-base-v2",texts=["Hello","How are you?"])The OxAPI offers a variety of models from natural language processing for your convenience.We provide highly optimized and production-ready endpoints to serve artificial intelligence for
your deep tech applications.Hosting and running such models is very difficult and time-consuming. At OxAPI, you get all the
latest NLP technology for building applications without any of the inconveniences that come with
it.We provide open-source and proprietary models with transparent and fair pricing as
high-performance endpoints. Each model is documented in detail and offers an easy-to-use and
understandable API. We take care of hosting, hardware selection, and optimization for you.
The results are some of the fastest models on the market. OxAPI, from developers, for
developers.InstallationYou don't need this source code unless you want to modify the package. If you just
want to use the package, just run:pipinstall-UoxapiInstall from source with:pythonsetup.pyinstallDocumentationFor the full documentation of the API itself, please visit theOxAPI documentation.If you want to check the documentation of this package, visit thedocsAdditionally, you find an interative tutorial on Colab:AudienceThis package is intended for anyone working with natural language processing.You need a reliable and scalable API to build your application onYou need the latest models at your fingertipsYou don't need thousands of models, only a few really good onesYou need results blazingly fast 🚀You don't want to bother creating and maintaining GPU clustersYou want someone else to take care of all the dirtyworkYou have one or more of the following usecases:Natural Language UnderstandingNamed Entity RecognitionEmotion ClassificationContent FilteringSpell CheckingIntention ClassifcationEncodingTopic ClassificationNatural Language GenerationParaphrasingSpell-checkingCode GenerationSummarizationProduct DescriptionAd-GenerationAnd many more ...The list of use-cases will be expanded upon in the future. We will expand our offer with models from
computer vision and audio eventually in the coming weeks and months. Stay tuned!ReliabilityWe see reliability and speed as our core assets. Visit ourstatuspageon recent updates and healthchecks.FAQIf you have any questions, please check theFAQsection of our hompage.UsageAPI keyThe library needs to be configured with your account's secret key. Either set it as theOXAPI_KEYenvironment variable before using the library:exportOXAPI_KEY='sk-...'Or setoxapi.api_keyto its value:importoxapioxapi.api_key="sk-..."CompletionfromoxapiimportCompletion# Performing API callcompletion=Completion.run(model="gpt-neo-2-7b",prompt="My name is Tim.\nSentiment: Neutral\nIt is such a lovely day.\nSentiment: Positive\nAlthough I am in a bad mood\nSentiment:",max_length=2,do_sample=False,eos_words=["\n"])# Fetching resultres=completion.format_result(result_format="str")print(completion.result)Output:{'results': ['Neutral\n']}ClassificationfromoxapiimportClassification# Performing API callclassification=Classification.run(model="dialog-content-filter",texts=["I want to kill myself.","I want to kill myself.<sep>You should not do that!","I want to kill myself.<sep>Do it!"])# Fetching resultres=classification.format_result(result_format="pd")print(res)Output:text label          confidence_score
0                             I want to kill myself.  unsafe      0.9772329101403038
1  I want to kill myself.<sep>You should not do t...  safe        0.9736578740966625
2                  I want to kill myself.<sep>Do it!  unsafe      0.9266854663680397EncodingfromoxapiimportEncoding# Performing API callencoding=Encoding.run(model="all-mpnet-base-v2",texts=["Hello","How are you?"])# Fetching resultprint(encoding.result)Output:{'results': [[
   -0.017791748046875,
   -2.980232238769531e-07,
   -0.022003173828125,
   0.02105712890625,
   -0.06695556640625,
   -0.02435302734375,
   -0.0174713134765625,
   ...
    -0.0011529922485351562]]
}TransformationfromoxapiimportTransformation# Performing API calltransformation=Transformation.run(model="punctuation-imputation",texts=["hello my name is tim i just came back from nyc how are you doing"])# Fetching resultprint(transformation.result)Output:{'results': ['Hello my name is Tim. I just came back from NYC. How are you doing?']}PipelinefromoxapiimportPipeline# Performing API callpipeline=Pipeline.run(model="en-core-web-lg",texts=["Hi there!"])# Fetching resultprint(pipeline.result)Output:{'results': [{'text': 'Hi there!',
   'ents': [],
   'sents': [{'start': 0, 'end': 9}],
   'tokens': [{'id': 0,
     'start': 0,
     'end': 2,
     'tag': 'UH',
     'pos': 'INTJ',
     'morph': '',
     'lemma': 'hi',
     'dep': 'ROOT',
     'head': 0},
    {'id': 1,
     'start': 3,
     'end': 8,
     'tag': 'RB',
     'pos': 'ADV',
     'morph': 'PronType=Dem',
     'lemma': 'there',
     'dep': 'advmod',
     'head': 0},
    {'id': 2,
     'start': 8,
     'end': 9,
     'tag': '.',
     'pos': 'PUNCT',
     'morph': 'PunctType=Peri',
     'lemma': '!',
     'dep': 'punct',
     'head': 0}],
   'sents_text': ['Hi there!']}]
}Asynchronous call pipelineWithoxapi-pythonpackage is possible to make calls to OxAPI in parallel. TheAsyncCallPipeclass takes as input a list of API calls each set through thepreparefunction to be executed by the pipeline.fromoxapi.asyncimportAsyncCallPipefromoxapiimportCompletionfromoxapiimportClassificationfromoxapiimportTransformationfromoxapiimportPipeline# Set up API callscl=Classification.prepare(model="dialog-content-filter",texts=["I want to kill myself."])cm=Completion.prepare(model="gpt-neo-2-7b",prompt="Hello there, ",max_length=25,do_sample=True,eos_words=["\n"])tr=Transformation.prepare(model="punctuation-imputation",texts=["hello my name is tim i just came back from nyc how are you doing"])pl=Pipeline.prepare(model="en-core-web-lg",texts=["Hi there!"])# Building and running the asynchronous pipeasy=AsyncCallPipe([cl,cm,tr,pl])res=asy.run()# Fetching the result of the first call in the listprint(res[0].format_result(result_format="pd"))Output:text label          confidence_score
0                             I want to kill myself.  unsafe      0.9772329101403038It is possible to add API calls to the asynchronous pipe even after its instantiation though theaddfunction. There's also theflushfunction to clear the list in the pipe.fromoxapi.asyncimportAsyncCallPipefromoxapiimportEncoding# Instantiate an empty asynchornous pipeasy=AsyncCallPipe()# Set up API call and add it to the pipeen=Encoding.prepare(model="all-mpnet-base-v2",texts=["Hello","How are you?"])asy.add(en)# running the asynchronous piperes=asy.run()Package Structure├── oxapi
│   ├── abstract                
│   │   └── api.py              # Non-instantiable, super classes for API calls
│   ├── nlp                     
│   │   ├── classification.py   # NLP Classification package
│   │   ├── completion.py       # NLP Completion package
│   │   ├── encoding.py         # NLP Encoding package
│   │   ├── pipeline.py         # NLP Pipeline package
│   │   └── transformation.py   # NLP Transformation package
│   ├── utils.py                # General utilities
│   ├── async.py               # package for asynchronous API calls
│   └── error.py                # Custom exceptions module
├── tests                       # Tests
└── docs_src                    # Documentation source filesCredits(C) 2022 Oxolo GmbH