# How to use Functions?

### **Step 1** <a href="#step-1" id="step-1"></a>

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

### **Step 2** <a href="#step-2" id="step-2"></a>

Create your PROMPT Function:

* create a basic fetch call for the weather of any location
* create a serper&#x20;

**You can find more** [**examples here**](https://gooey.ai/functions/examples)

#### A basic Weather API call ([link here](https://gooey.ai/functions/current-weather-rxmquy60p1vq/))

```javascript
async ({ lat, long }) => {
  // Use Open-Meteo's public API for fetching weather data
  let url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${long}&current_weather=true`;
  let response = await fetch(url);
  let data = await response.json();
  return { weather: data.current_weather };
};
```

#### An API call for Serper  - a service for google search ([link here](https://gooey.ai/functions/google-search-without-api-key-tey6zrx2vzvm/))

```javascript
async ({ query }) => {
  var myHeaders = new Headers();
  myHeaders.append("X-API-KEY", "your API key");
  myHeaders.append("Content-Type", "application/json");
  
  var raw = JSON.stringify({
    "q": query
  });
  
  var requestOptions = {
    method: 'POST',
    headers: myHeaders,
    body: raw,
    redirect: 'follow'
  };
  
  let ret = await fetch("https://google.serper.dev/search", requestOptions);

  return { search_results: await ret.json() };
};

```

### **Step 3** <a href="#step-3" id="step-3"></a>

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.

### **Step 4** <a href="#step-5" id="step-5"></a>

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

Head over to the example below:

{% embed url="<https://gooey.ai/copilot/farmerchat-with-current-weather-data-qfzn662xf06v/>" %}

Check the Functions option, and choose “PROMPT” from the dropdown and add your Saved example. And then hit "SUBMIT!

<figure><img src="https://2450152260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNWqgWAjD0VVJgjYDpsN5%2Fuploads%2Fij49AYcg2DKXL6tj0RhZ%2Fimage.png?alt=media&#x26;token=769204ef-ecae-4d79-8ef8-7b5cb85c9fb6" alt=""><figcaption></figcaption></figure>

*You can check your Functions output in the Workflow at the end of the page in "Details" section.*

<figure><img src="https://docs.gooey.ai/~gitbook/image?url=https%3A%2F%2F662560811-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F5BFP5RUm6rTLXk8wUSTf%252Fuploads%252FenY8Js0Pe22WJWCN5Ook%252FScreenshot%25202024-08-09%2520at%25202.02.41%25E2%2580%25AFPM.png%3Falt%3Dmedia%26token%3D7386368f-50b3-4def-b495-977fcb610b40&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=c63c07c8&#x26;sv=1" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2450152260-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNWqgWAjD0VVJgjYDpsN5%2Fuploads%2F2TQxiDyHeMPT2HwFEV3C%2FScreenshot%202024-10-19%20at%201.15.29%E2%80%AFAM.png?alt=media&#x26;token=ad9cefcb-08c9-4ffc-a9b3-634ef22c2567" alt=""><figcaption></figcaption></figure>
