# Chatbot with Context

> Implement context for your chatbot solution
>
> - **Canonical URL:** https://www.builderbot.app/en/tutorials/chatbot-with-gemini
> - **Documentation Index:** https://www.builderbot.app/llms.txt
> - **Full Corpus:** https://www.builderbot.app/llms-full.txt

The gemini model is a generous and valuable resource to use if it comes to creating a product with AI that has both vision and text generation and without spending a penny is what we want.

To start remember to install the gemini plugin and have your [Google Api key](https://aistudio.google.com/app/apikey)

---

## Install Gemini

We started the installation of a package that will help you to implement the Gemin power in builderbot.

```bash
pnpm install @builderbot-plugins/gemini-layer
```

  [More info about it](https://github.com/codigoencasa/bot-plugins/tree/main/packages/gemini)

---

## Context Example

Sometimes we don't want to place so many keywords or answers in validations of our flows, we want some freedom when it comes to responding, that's why we have the gemini plugin to respond based on a context

the context indicates between key value, the different scenarios in which the user may be when interacting with the assistant

__context__: It is the object that will contain all the necessary properties you need.

```ts (layers/context.layer.ts)
import { geminiLayer } from "@builderbot-plugins/gemini-layer"

export default async (...bot: any) => await geminiLayer({
    context: {
        name: 'your name',
        email: 'your email',
        summary: 'your summary'
        // and more properties
    }
}, bot)
```
```ts (flows/context.flow.ts)
import { EVENTS, addKeyword } from "@builderbot/bot"
import contextLayer from "./layers/context.layer"

export default addKeyword(EVENTS.ACTION)
    .addAction(contextLayer)
```
```ts (app.ts)
import { createBot, createProvider, createFlow, MemoryDB } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'

import contextFlow from "./flows/context.flow"

/* SOME STUFF IMPORTS */

await createBot({
    database: new MemoryDB(),
    provider: createProvider(BaileysProvider),
    flow: createFlow([...othersFlows, contextFlow])
})
```

---

## Vision Example

| Field           | Description                                                                                           |
|-----------------|-------------------------------------------------------------------------------------------------------|
| `vision`        | true                                                                                                  |
| `visionPrompt`  | What you want the model to see                                                                       |
| `image_path`    | The route where the image will be downloaded to be analyzed later                                     |
| `cb`            | A callback that receives the same interface as addAction and which returns an answer in the state    |

```ts (layers/image.layer.ts)
import { geminiLayer } from "@builderbot-plugins/gemini-layer"

const visionPrompt = 'Give me a brief summary of what you see in the picture'

export default async (...bot: any) => await geminiLayer({
    vision: true,
    visionPrompt,
    image_path: './',
    cb: async (_, { state, gotoFlow }) => {
        const { answer } = state.getMyState()
        console.log('answer about image', answer)

        if (answer === 'anything else you want to validate') {
            return gotoFlow('any flow you want to go')
        }
    }
}, bot)
```
```ts (flows/image.flow.ts)
import { EVENTS, addKeyword } from "@builderbot/bot"
import imageLayer from "./layers/image.layer"

export default addKeyword(EVENTS.MEDIA)
    .addAction(imageLayer)
```
```ts (app.ts)
import { createBot, createProvider, createFlow, MemoryDB } from '@builderbot/bot'
import { BaileysProvider } from '@builderbot/provider-baileys'

import imageFlow from "./flows/image.flow"

/* SOME STUFF IMPORTS */

await createBot({
    database: new MemoryDB(),
    provider: createProvider(BaileysProvider),
    flow: createFlow([...othersFlows, imageFlow])
})
```

---
