File size: 5,203 Bytes
eda43d3
ea385eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eda43d3
ea385eb
eda43d3
ea385eb
eda43d3
ea385eb
eda43d3
ea385eb
eda43d3
ea385eb
 
 
eda43d3
c9742ff
039d3dc
 
cb43bb3
 
ea385eb
eda43d3
ea385eb
eda43d3
ea385eb
eda43d3
 
ea385eb
 
eda43d3
ea385eb
eda43d3
 
ea385eb
eda43d3
ea385eb
 
c9742ff
ea385eb
eda43d3
ea385eb
 
c9742ff
 
ea385eb
eda43d3
ea385eb
 
 
c9742ff
 
 
 
 
 
 
 
 
 
 
 
ea385eb
eda43d3
 
ea385eb
eda43d3
d05983f
 
c9742ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea385eb
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
---
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 and execute the api call 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"""<question>{}</question>
<doc/code/any tag that explains the task at hand>"""
```

### 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 = "<question>Perform api call to do task k</question><python_code>"
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"""
<api_doc>
{swagger_docs}
</api_doc>
<question>
{question}
</question>
<response>
"""
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