# Functions

In this guide, we will learn how to create a functions call on Gooey.AI and add it to our Gooey.AI workflows.&#x20;

We'll take the example of our Copilot Analysis Scripts. All copilots have an integrated LLM script to analyze various user data. This could be user location, question category, user sentiment, etc. Once you have the data, you might want to push it to your servers, or database, or combine it with your other services.&#x20;

### Scenario

We will take the "Gooey Chat Bot Analysis Script" in this example. This LLM script analyzes the incoming messages to our [Gooey.AI Support Bot](https://gooey.ai/copilot/the-gooeyai-support-bot-3dwfcqvcwl04/) and categorizes the user's query into buckets like API Usage, Pricing, Sales, etc.&#x20;

We want to push this output to our CRM so we get deeper analytics which helps us respond better to our customers.&#x20;

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FHlNWOJYv5VleKb8z9Wfe%2Fhubspot.jpg?alt=media&#x26;token=4faa5e5c-d33d-464d-a012-e4e426f2d6a3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FZWkhRZzo0Wpg9bq9grIp%2FScreenshot%202024-08-09%20at%201.54.11%E2%80%AFPM.png?alt=media&#x26;token=2206d69a-a409-4ad5-9dc7-d82c1f5003bb" alt=""><figcaption><p>Gooey Support Bot's Analysis script, on the left is the LLM prompt with the incoming message and on the right is the category output</p></figcaption></figure>

{% embed url="<https://gooey.ai/compare-large-language-models/gooey-bot-chat-analysis-script-27lrilywfzmv/>" %}
LINK TO THE LLM ANAYLSIS SCRIPT
{% endembed %}

## How do you add functions to your Gooey workflows?

### **Step 1**

Head over the [Functions workflow](https://gooey.ai/functions/)

### **Step 2**

Create your POST Request with AFTER Function:

Here is a basic fetch call, you can copy or edit this code as per your needs, and paste it in the code editor on the Functions workflow.&#x20;

**Currently, we have added httpbin for our POST request, you can change this for your preferred API. You can find more** [**examples here**](https://gooey.ai/functions/examples)

{% code title="A basic fetch call" lineNumbers="true" %}

```javascript
async (variables) => {
  const res = await fetch("https://httpbin.org/post", {
    method: "POST",
    body: JSON.stringify(variables),
    headers: {
      "Content-Type": "application/json",
    },
  });
  return { response: await res.json() };
};
```

{% endcode %}

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2Fo99TkOjQ7rreN36fkArX%2FScreenshot%202024-08-09%20at%209.58.52%E2%80%AFPM.png?alt=media&#x26;token=0058c960-4945-4e4b-819a-8dc2b0f96c17" alt=""><figcaption><p>Functions workflow with the code editor to the left</p></figcaption></figure>

### **Step 3**

Add your relevant variables.&#x20;

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FeYPBhyFfJJ7OkbPgAJNn%2Fvariables.gif?alt=media&#x26;token=28d2b8c1-7524-4fd2-9af4-034af920ea7e" alt="" width="375"><figcaption></figcaption></figure>

### **Step 4**

Hit Submit, if your code is working fine you will get your outputs on the right side. Use the “Save as New” button and update the run name.

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FunLUXLAspI2NrXjuKuJ1%2Fsaveasnew.gif?alt=media&#x26;token=49c3f377-9d4e-4fc3-bb6a-be99dba5fc8b" alt=""><figcaption></figcaption></figure>

### **Step 5**

Now head over to the Gooey workflow where you want to add the saved functions.

Head over to the example below:&#x20;

{% embed url="<https://gooey.ai/compare-large-language-models/gooey-bot-chat-analysis-script-27lrilywfzmv/>" %}

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FlqIRMzOuW8LSq75Fubz2%2FScreenshot%202024-08-06%20at%2011.36.19%E2%80%AFAM.png?alt=media&#x26;token=5fda4c07-5b3b-4a0f-a26d-be7838d9f317" alt=""><figcaption></figcaption></figure>

Check the Functions, choose “AFTER” and add your Saved example. And then hit "SUBMIT!&#x20;

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FnLSK2WdtRtmEItipQurV%2FScreenshot%202024-08-06%20at%2011.36.19%E2%80%AFAM.png?alt=media&#x26;token=877df264-b398-43c1-b8a1-9aafd06e04ce" alt=""><figcaption></figcaption></figure>

You can check your Functions output in the Workflow at the end of the page in "Details" section.&#x20;

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FenY8Js0Pe22WJWCN5Ook%2FScreenshot%202024-08-09%20at%202.02.41%E2%80%AFPM.png?alt=media&#x26;token=7386368f-50b3-4def-b495-977fcb610b40" alt=""><figcaption></figcaption></figure>

### How do I find all the available functions and how can I contribute? <a href="#id-86mplbjxoi5t" id="id-86mplbjxoi5t"></a>

All the functions are available here:

{% embed url="<https://gooey.ai/functions/examples/>" %}

Choose any of the Examples and Fork them!

<figure><img src="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2F6ucdBO4VWDBMjKXSruP9%2Fexamplesection.gif?alt=media&#x26;token=fa2dc501-e94a-42d1-946f-8ffcde0d12b3" alt=""><figcaption></figcaption></figure>

### More resources

<table data-view="cards"><thead><tr><th></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><h4>Read more about GOOEY.AI functions</h4></td><td><a href="https://app.gitbook.com/s/leYcqBx5FRZcVr3wI4f4/fun-fun-functions">Fun fun functions!</a></td><td><a href="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FKgEggjJkOX44C5A2ppd6%2Fgooey.ai%20-%20cute%20robot%20doing%20javascript%20vintage%20p...gazine%20advertisement%20muted%20colorful%20illustration.png?alt=media&#x26;token=5a1e10a5-a4bd-405d-aeb7-5666307a2741">gooey.ai - cute robot doing javascript vintage p...gazine advertisement muted colorful illustration.png</a></td></tr><tr><td><h4>Connect API to LLM Generator</h4></td><td><a href="https://gooey.ai/compare-large-language-models/functions-make-a-haiku-with-iss-coordinates-k4vuehh6hhvo/">https://gooey.ai/compare-large-language-models/functions-make-a-haiku-with-iss-coordinates-k4vuehh6hhvo/</a></td><td><a href="https://662560811-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5BFP5RUm6rTLXk8wUSTf%2Fuploads%2FivzCST2M210WrIqE2IFJ%2Fgooey.ai%20-%20cute%20robots%20and%20aliens%20shaking%20hands%20...gazine%20advertisement%20muted%20colorful%20illustration.png?alt=media&#x26;token=556e9d25-0e0c-4da3-9500-5e3d8f337340">gooey.ai - cute robots and aliens shaking hands ...gazine advertisement muted colorful illustration.png</a></td></tr><tr><td></td><td></td><td></td></tr></tbody></table>
