--- license: apache-2.0 language: - en metrics: - accuracy tags: - api - open-api - swagger - api doc - api call - code - instruction_tuned - basemodel - pytorch - RL Tuned - text-generation-inferenc library_name: transformers pipeline_tag: text-generation --- # pip-api-expert [pipableAi](https://pipable.ai/) [colab_notebook]() ## What have we built? A 1.3 bn state of the art model for api calling , documentation, testing management. The tasks that the model can accomplish are the following. ```markdown 1. Convert any bad format text to open api format. 2. Convert any bad format text to mark down format. 3. Given docs and questions in natural language, generate api calls in python. ``` ## How we built it? We used a simulator and a form of policy gradient to train the model to self instruct itself to make documents and then perform executable calls on the document. ## License The model is open source under apache 2.0. License ## Usage ### Installation ```bash pip install transformers pip install accelerate ``` ### Prompt ```python prompt = f"""{} """ ``` ### PyTorch ```python from transformers import AutoModelForCausalLM, AutoTokenizer from accelerate import Accelerator import torch path = "PipableAI/pip-api-expert" model =AutoModelForCausalLM.from_pretrained(path,torch_dtype=torch.bfloat16,device_map="auto") tokenizer = AutoTokenizer.from_pretrained(path) prompt = "Perform api call to do task k" inputs = tokenizer(prompt, return_tensors="pt").to("cuda") outputs = model.generate(**inputs, max_new_tokens=1200) doc = ( tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True) ) print(doc) ``` ## Examples ### markdown documentation format for api docs ```python swagger_docs = """ Method access HTTP JavaScript Python Java POST https://slack.com/api/chat.postMessage Required scopes Bot tokens chat:write User tokens chat:write chat:write:user chat:write:bot Legacy bot tokens bot Content types application/x-www-form-urlencoded application/json Rate limits Special Arguments Required arguments token token ·Required Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter. Example xxxx-xxxxxxxxx-xxxx channel string ·Required Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details. Example C1234567890 At least one of attachmentsblockstext One of these arguments is required to describe the content of the message. If attachments or blocks are included, text will be used as fallback text for notifications only. attachments string blocks blocks[] as string text string How this field works and whether it is required depends on other fields you use in your API call. See below for more detail. Example Hello world Optional arguments as_user boolean ·Optional (Legacy) Pass true to post the message as the authed user instead of as a bot. Defaults to false. Can only be used by classic Slack apps. See authorship below. Example true icon_emoji string ·Optional Emoji to use as the icon for this message. Overrides icon_url. Example :chart_with_upwards_trend: icon_url string ·Optional URL to an image to use as the icon for this message. Example http://lorempixel.com/48/48 link_names boolean ·Optional Find and link user groups. No longer supports linking individual users; use syntax shown in Mentioning Users instead. Example true metadata string ·Optional JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace. Example {"event_type": "task_created", "event_payload": { "id": "11223", "title": "Redesign Homepage"}} mrkdwn boolean ·Optional Disable Slack markup parsing by setting to false. Enabled by default. Default true Example false parse string ·Optional Change how messages are treated. See below. Example full reply_broadcast boolean ·Optional Used in conjunction with thread_ts and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to false. Example true thread_ts string ·Optional Provide another message's ts value to make this message a reply. Avoid using a reply's ts value; use its parent instead. unfurl_links boolean ·Optional Pass true to enable unfurling of primarily text-based content. Example true unfurl_media boolean ·Optional Pass false to disable unfurling of media content. Example false username string ·Optional Set your bot's user name. Example My Bot """ question = """ Convert the above docs to markdown format. """ prompt = f""" {swagger_docs} {question} """ inputs = tokenizer(prompt, return_tensors="pt").to("cuda") outputs = model.generate(**inputs, max_new_tokens=1800) doc = ( tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True) ) print(doc) ``` ### Team Avi Kothari, Pratham Gupta, Ritvik Aryan Kalra, Rohan Bhatial, Soham Acharya