Skip to content

Commit 5cfd35b

Browse files
committed
Updating prompt
1 parent 8a8e3e5 commit 5cfd35b

36 files changed

+501
-152
lines changed

packages/component_code_gen/code_gen/generate_component_code.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def generate_code(app, prompt, templates, parsed_common_files, urls_content, tri
3838
docs_meta = {} # XXX - temporarily disable supabase docs
3939
results = []
4040

41-
auth_details = "## Auth details\n\nThese details come directly from the app configuration in Pipedream. Prioritize this information over any other information you find in the app's docs, since this section is specific to Pipedream."
41+
auth_details = "<AuthDetails>\n\nThese details come directly from the app configuration in Pipedream. Prioritize this information over any other information you find in the app's docs, since this section is specific to Pipedream."
4242
auth_meta = db.get_app_auth_meta(app)
4343
auth_type = auth_meta.get('auth_type')
4444
if auth_type == "keys":
@@ -48,7 +48,9 @@ def generate_code(app, prompt, templates, parsed_common_files, urls_content, tri
4848
elif auth_type == "oauth":
4949
auth_details += f"{app} is an OAuth app. The `this` object exposes the OAuth access token in the variable `this.#{app.name_slug}.$auth.oauth_access_token`. When you make an API request, use the format from the \"Auth example\" section below."
5050
if auth_meta.get('component_code_scaffold_raw'):
51-
auth_details = f"\n\n## Auth example\n\nHere's example Node.js code to show how authentication is done in {app}:\n\n{auth_meta['component_code_scaffold_raw']}\n\n"
51+
auth_details += f"\n\n## Auth example\n\nHere's example Node.js code to show how authentication is done in {app}:\n\n{auth_meta['component_code_scaffold_raw']}\n\n"
52+
53+
auth_details += "</AuthDetails>"
5254

5355
normal_order = False
5456
for i in range(tries):
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
1-
additional_rules = """## Additional rules for actions
1+
additional_rules = """<AdditionalRules>
22
33
1. Always import the app file like this:
44
5+
```javascript
56
import appName from "../../appName.app.mjs";
7+
```
8+
9+
and pass the app file as a prop to the component:
10+
11+
```javascript
12+
export default {
13+
props: {
14+
appName,
15+
},
16+
// rest of the component ...
17+
}
18+
```
619
720
2. `return` the final value from the step. The data returned from steps must be JSON-serializable. The returned data is displayed in Pipedream. Think about it: if you don't return the data, the user won't see it.
821
922
3. Always use this signature for the run method:
1023
24+
```javascript
1125
async run({ $ }) {
12-
// your code here
26+
// you must fill in the actual code here
1327
}
28+
```
1429
15-
Always pass { $ }, even if you don't use them in the code.
30+
Always pass `{ $ }` in the arguments to the `run` method, even if you don't use it in the code.
1631
17-
4. Remember that `@pipedream/platform` axios returns a Promise that resolves to the HTTP response data. There is NO `data` property in the response that contains the data. The data from the HTTP response is returned directly in the response, not in the `data` property. Think about it: if you try to extract a data property that doesn't exist, the variable will hold the value `undefined`. You must return the data from the response directly and extract the proper data in the format provided by the API docs.
32+
4. `@pipedream/platform` axios returns a Promise that resolves to the HTTP response data. There is NO `data` property in the response that contains the data. The data from the HTTP response is returned directly in the response, not in the `data` property. Think about it: if you try to extract a data property that doesn't exist, the variable will hold the value `undefined`. You must return the data from the response directly and extract the proper data in the format provided by the API docs.
1833
1934
For example, do this:
2035
36+
```javascript
2137
const response = await axios(this, {
2238
url: `https://api.stability.ai/v1/engines/list`,
2339
headers: {
2440
Authorization: `Bearer ${this.dreamstudio.$auth.api_key}`,
2541
},
2642
});
27-
// process the response data. response.data is undefined
43+
// process the `response` as the return data. `response.data` is undefined, data is directly in `response`
44+
```
2845
2946
not this:
3047
48+
```javascript
49+
// this is incorrect — there is no `data` property in the response
3150
const { data } = await axios(this, {
3251
url: `https://api.stability.ai/v1/engines/list`,
3352
headers: {
3453
Authorization: `Bearer ${this.dreamstudio.$auth.api_key}`,
3554
},
36-
});"""
55+
});
56+
```
57+
58+
</AdditionalRules>"""
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
export_summary = """## Export summary
1+
export_summary = """<ExportSummary>
22
3-
A short summary should be exported before the end so that the user can quickly read what has happened. This is done by calling `$.export("$summary", "Your summary here")`. This is not optional.
3+
You must call `$.export` to export a short text summary near the end of the `run` method so the user knows the call was successful. This is done by calling `$.export("$summary", "Your summary here")`.
44
5-
The summary should contain relevant metadata about the object that was created, updated, or deleted. For example, if you are creating a new issue, you should include the issue name or ID in the summary.
5+
The summary should contain relevant metadata about the object that was created, updated, or deleted. For example, if you are creating a new issue, you should include the issue name or ID in the summary. Include information here that you think will be most relevant for the user reading the summary.
66
7-
```
8-
`$.export("$summary", `Created issue ${name}`)
7+
Generally, this should happen immediately before you return the data at the end of the component's `run` method.
8+
9+
```javascript
10+
$.export("$summary", `Created issue ${name}`)
11+
return data
912
```
1013
11-
Include information here that you think will be most relevant for the user.
14+
</ExportSummary>
1215
"""
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1-
introduction = """## Instructions
1+
introduction = """<Instructions>
22
3-
Your goal is to create Pipedream Action Components. Your code should solve the requirements provided below.
3+
<Goal>
4+
Your goal is to create Pipedream action components, defined in the <Definitions> section below.
45
5-
Other GPT agents will be reviewing your work, and will provide feedback on your code. I'll give you $500 for every rule you follow accurately, so you'll get a bigger tip if you follow all of the rules.
6+
Your code should solve the requirements provided below.
67
7-
## Pipedream components
8+
Think step by step:
89
9-
All Pipedream components are Node.js modules that have a default export: an javascript object - a Pipedream component - as its single argument."""
10+
1. Review the requirements
11+
2. Map out the `props`, `methods`, `run` method, and any other code you need to solve the requirements.
12+
3. Review whether you need async options for props (see the <AsyncOptions> section below)
13+
4. Review all of the rules carefully before producing code
14+
5. Produce full, complete, working code. This code is going straight to production.
15+
6. Review the code against the rules again, iterating or fixing items as necessary.
16+
7. Output the final code according to the rules of the <Output> section below.
17+
18+
Other GPT agents will be reviewing your work, and will provide feedback on your code. Please review it before producing output.
19+
</Goal>
20+
21+
<Defintions>
22+
<PipedreamActionComponents>
23+
24+
All Pipedream components are Node.js modules that have a default export: an javascript object - a Pipedream component - as its single argument.
25+
26+
See the <Rules>, <AsyncOptions>, <AdditionalRules>, and other sections below for details on how to structure components.
27+
28+
</PipedreamActionComponents>
29+
</Definitions>
30+
31+
</Instructions>"""

packages/component_code_gen/templates/actions/main_example.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
main_example = """## OpenAI example component
1+
main_example = """<Example>
2+
<OpenAI>
23
3-
Here's an example component:
4+
Here's an example Pipedream action for OpenAI that lists all models available to the user:
45
5-
```
6+
```javascript
67
import openai from "../../openai.app.mjs"
78
import { axios } from "@pipedream/platform"
89
@@ -26,4 +27,7 @@
2627
return response
2728
},
2829
};
29-
```"""
30+
```
31+
</OpenAI>
32+
</Example>
33+
"""

packages/component_code_gen/templates/actions/other_example.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
other_example = """## Slack API example component
1+
other_example = """<AdditionalExample>
2+
<Slack>
23
34
Here's an example Pipedream component that makes a test request against the Slack API:
45
5-
```
6+
```javascript
67
import slack from "../../slack.app.mjs"
78
import { axios } from "@pipedream/platform"
89
@@ -41,18 +42,22 @@
4142
return response
4243
},
4344
};
45+
```
4446
4547
Notice this section:
4648
49+
```javascript
4750
data: {
4851
channel: this.channel,
4952
text: this.text,
5053
},
54+
```
5155
52-
This shows you how to pass the values of props (e.g. this.channel and this.text) as params to the API. This is one of the most important things to know: you MUST generate code that adds inputs as props so that users can enter their own values when making the API request. You MUST NOT pass static values. See rule #2 below for more detail.
56+
This shows you how to pass the values of props (e.g. `this.channel` and `this.text`) as params to the API. This is one of the most important things to know: you MUST generate code that adds inputs as props so that users can enter their own values when making the API request. You MUST NOT pass static values. See the <Rules> for more information.
5357
5458
The code you generate should be placed within the `run` method of the Pipedream component:
5559
60+
```javascript
5661
import { axios } from "@pipedream/platform";
5762
5863
export default {
@@ -69,4 +74,8 @@
6974
$.export("$summary", "Your summary here")
7075
return response
7176
},
72-
};"""
77+
};
78+
```
79+
80+
</Slack>
81+
</AdditionalExample>"""
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
additional_rules = """## Additional rules
1+
additional_rules = """<AdditionalRules>
22
3-
### Generate propDefinitions and methods for ALL requirements
3+
1. Generate `propDefinitions` and `methods` for ALL requirements
44
5-
The instructions should note the actions and source components that are required for the app. The code generator should generate the propDefinitions and methods for ALL requirements. Think about it: this way other agents will be able to use the shared props + methods in the action and source components. Double-check your output to make sure that the propDefinitions and methods are generated for ALL requirements.
5+
The instructions should note the actions and source components that are required for the app. The code generator should generate the `propDefinitions` and `methods` for ALL requirements. Think about it: this way other agents will be able to use the shared props + methods in the action and source components. Double-check your output to make sure that the propDefinitions and methods are generated for ALL requirements.
6+
</AdditionalRules>
67
"""
Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
1-
introduction = """## Instructions
1+
introduction = """<Instructions>
22
3-
Your goal is to create Pipedream app files. Your code should solve the requirements provided below.
3+
<Goal>
4+
Your goal is to create Pipedream app files, defined in the Definition section below.
45
5-
DO NOT remove any propDefinitions or methods that already exist. You can only write more, if required.
6+
Your code should solve the requirements provided below.
67
7-
Other GPT agents will be reviewing your work, and will provide feedback on your code. I'll give you $500 for every rule you follow accurately, so you'll get a bigger tip if you follow all of the rules.
8+
Think step by step:
89
9-
## Pipedream App files
10+
1. Review the requirements
11+
2. Map out the props and methods you need to solve the requirements
12+
3. Review whether you need async options for props (see the <AsyncOptions> section below)
13+
4. Review all of the rules carefully before producing code
14+
5. Produce full, complete, working code. This code is going straight to production.
15+
6. Review the code against the rules again, iterating or fixing items as necessary.
16+
7. Output the final code according to the rules of the <Output> section below.
17+
18+
Other GPT agents will be reviewing your work, and will provide feedback on your code. Please review it before producing output.
19+
</Goal>
20+
21+
<Definition>
22+
<PipedreamAppFiles>
1023
1124
All Pipedream app files are Node.js modules that have a default export: a javascript object - a Pipedream app - as its single argument.
1225
13-
All app objects have four properties: type, app, propDefinitions, and methods:
26+
All app objects have four properties: `type`, `app`, `propDefinitions`, and `methods`:
1427
1528
- The `type` property is always set to "app".
1629
- The `app` property is the name of the app, e.g. "google_sheets".
1730
- The `propDefinitions` property is an object that contains the props for the app.
18-
- The methods property is an object that contains the methods for the app.
31+
- The `methods` property is an object that contains the methods for the app.
32+
33+
These props and methods are shared across components for this app file. You'll need to generate props and methods for ALL requirements for all components that you're passed below.
34+
</PipedreamAppFiles>
35+
</Definition>
36+
<Output>
37+
Output Node.js code.
38+
39+
DO NOT remove any `propDefinitions` or `methods` that already exist. You can only write more, if required.
40+
</Output>
1941
20-
These props and methods are shared across components for this app file. You'll need to generate props and methods for ALL requirements for all components that you're passed below."""
42+
</Instructions>"""

packages/component_code_gen/templates/apps/main_example.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
main_example = """## Example app file for Raindrop
1+
main_example = """<Examples>
2+
<Raindrop>
23
34
Here's an example Pipedream app for Raindrop:
45
@@ -87,15 +88,17 @@
8788
},
8889
};
8990
```
91+
</Raindrop>
92+
<GeneralExample>
93+
App files contain a `propDefinitions` property, which contains the definitions for the props of the app.
9094
91-
This object contains a `propDefinitions` property, which contains the definitions for the props of the app.
92-
93-
The propDefinitions object contains two props: collectionId and raindropId. The collectionId prop is a string prop. The raindropId prop is also a string prop. The propDefinitions object also contains an `options` method. The `options` method is an optional method that can be defined on a prop. It is used to dynamically generate the options for a prop and can return a static array of options or a Promise that resolves to an array of options.
95+
The `propDefinitions` object contains two props: `collectionId` and `raindropId`. The `collectionId` prop is a string prop. The `raindropId` prop is also a string prop. The `propDefinitions` object also contains an `options` method. The `options` method is an optional method that can be defined on a prop. It is used to dynamically generate the options for a prop and can return a static array of options or a Promise that resolves to an array of options.
9496
9597
This object contains a `props` property, which defines a single prop of type "app":
9698
9799
```
98100
import { axios } from "@pipedream/platform";
101+
99102
export default {
100103
type: "app",
101104
app: "the_app_name",
@@ -141,4 +144,7 @@
141144
},
142145
},
143146
}
144-
```"""
147+
```
148+
</GeneralExample>
149+
</Examples>
150+
"""

packages/component_code_gen/templates/apps/methods.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
methods = """## Methods
1+
methods = """<Methods>
22
3-
The `methods` property contains helper methods. These methods can be called by other files.
3+
The `methods` property contains helper methods that compnents can use. These methods can be called by components that include the app file.
44
5-
A `_baseUrl` method is always required. It should return the base URL endpoint for the API.
5+
### _baseUrl method
66
7-
A `async _makeRequest` method is always required. It contains the code that makes the API request. It takes one argument, a single object named `opts`.
7+
Always include a `_baseUrl` method. It should return the base URL endpoint for the API, defined by the OpenAPI spec or the API documentation.
8+
9+
### _makeRequest method
10+
11+
Always include an `async _makeRequest` method. It contains the code that makes the API request. It takes one argument, a single object named `opts`.
812
913
`opts` is an object that contains the parameters of the API request. When calling a component method with multiple parameters, you should pass them as a single object, using the Javascript spread syntax and destructuring when able to.
1014
@@ -32,7 +36,7 @@
3236
3337
An example `_makeRequest` method is shown below. It is a simple GET request that returns the data from the response.
3438
35-
```
39+
```javascript
3640
async _makeRequest(opts = {}) {
3741
const { $ = this, method = "GET", path = "/", headers, ...otherOpts } = opts;
3842
return axios($, {
@@ -48,7 +52,7 @@
4852
4953
Auxiliary methods, usually for CRUD operations call `_makeRequest` with the appropriate parameters. Please add a few methods for common operations, e.g. get and list. You can also add other methods that you think are useful. Similar to the `_makeRequest` method, these auxiliary methods should have only one parameter, an object, `opts`. It should always destructure `...otherOpts`. Be sure to always add this parameter. `return` directly when calling the `_makeRequest` method. Here's an example:
5054
51-
```
55+
```javascript
5256
async listObjects(opts = {}) {
5357
return this._makeRequest({
5458
path: "/objects",
@@ -70,4 +74,6 @@
7074
7175
If we find more data, the method should call itself with the listing method and the parameters for fetching the next set of data.
7276
73-
If we don't find more data, you should return the array of results."""
77+
If we don't find more data, you should return the array of results.
78+
79+
</Methods>"""

0 commit comments

Comments
 (0)