> For the complete documentation index, see [llms.txt](https://academy.gooey.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://academy.gooey.ai/ai-for-impact/module-9/how-to-use-functions.md).

# 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="/files/ZpKmAj3PYwZAWC0pC5DR" 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="/files/C8QIrruXH2N7XJEkg6zv" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://academy.gooey.ai/ai-for-impact/module-9/how-to-use-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
