OpenFn / apollo

GNU Lesser General Public License v2.1
0 stars 2 forks source link

Improve job prompt #81

Closed josephjclark closed 5 months ago

josephjclark commented 5 months ago

This PR tweaks the job prompt to try and get better openfn code.

Maybe we should update to GPT 4?

I'm not too concerned about quality yet, but I thought this would be an easy win (it wasn't, and I don't trust it)

Edit: check out what it's generated below - I am fairly happy with them all

josephjclark commented 5 months ago

From the prompt "What can I do?"

Based on the provided OpenFn DSL and the API documentation for the @openfn/language-http@5.0.0 adaptor, you can write job code that interacts with HTTP endpoints. Here's an example job code using the HTTP adaptor to make a GET request:

get('/myEndpoint', {
  query: { foo: 'bar', a: 1 },
  headers: { 'content-type': 'application/json' },
  authentication: { username: 'user', password: 'pass' }
});

This code snippet demonstrates how to use the get function from the HTTP adaptor to make a GET request to '/myEndpoint' with query parameters, custom headers, and authentication credentials.

Feel free to provide more details about the specific task you want to automate using OpenFn, and I can help you write the corresponding job code.

josephjclark commented 5 months ago

How do I remove a member from a mailling list? (mailchimp)

To remove a member from a mailing list using the @openfn/language-mailchimp@1.0.0 adaptor in OpenFn, you can use the deleteMember function provided by the adaptor. Here's an example of how you can remove a member from a mailing list:

deleteMember({
  listId: "your_list_id_here",
  subscriberHash: "subscriber_hash_here"
});

In the above code snippet:

Make sure to include this code within a job function in OpenFn to execute the operation.

josephjclark commented 5 months ago

How do I defer the post call to only call the webhook once a second?

To defer the post call to only execute the webhook once a second, you can introduce a delay using the fn operation provided by the OpenFn adaptor. Here's how you can modify your existing code to achieve this:

each(
  '$.no_ihs_number[*]',
  fn(state => {
    return new Promise(resolve => {
      setTimeout(() => {
        post('https://app.openfn.org/i/2c6ca3cd-d015-4b37-85ea-4c04ce72816b', {
          body: state.data,
          headers: { 'content-type': 'application/json' },
        })(state).then(() => {
          resolve(state);
        });
      }, 1000); // Delay of 1 second (1000 milliseconds)
    });
  })
);

In this code snippet:

Notes

This is spooky.

Here is the input code I gave it:

each(
  '$.no_ihs_number[*]',post(
          'https://app.openfn.org/i/2c6ca3cd-d015-4b37-85ea-4c04ce72816b', {
          body: state.data,
          headers: { 'content-type': 'application/json' },
        })
  })
)

And here is my actual solution:

each(
  '$.no_ihs_number[*]',
  fn(state => {
    return new Promise((resolve) => {
      setTimeout(() => {
        post(
          'https://app.openfn.org/i/2c6ca3cd-d015-4b37-85ea-4c04ce72816b', {
          body: state.data,
          headers: { 'content-type': 'application/json' },
        }, resolve)(state)
      }
        , 10000)
    })

  })

)