Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 82 additions & 82 deletions py/docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,68 +14,68 @@ This guide shows you how to get started with Genkit in a Python app.

## Requirements

* Python 3.12 or later. See [Download and
* Python 3.10 or later. See [Download and
install](https://www.python.org/downloads/) in the official Python docs.

* Node.js 20 or later (for the Genkit CLI and UI). See the below for a brief
guide on installing Node.

## Create and explore a sample project

1. Create a new project directory:
1. Create a new project directory:

```posix-terminal
mkdir genkit-intro && cd genkit-intro
```
```posix-terminal
mkdir genkit-intro && cd genkit-intro
```

2. (recommended) Create a Python virtual environment:
2. (recommended) Create a Python virtual environment:

```bash
python3 -m venv .
```
```bash
python3 -m venv .
```

(activate if necessary, depending on the environment)
(activate if necessary, depending on the environment)

```bash
source bin/activate # for bash
```
```bash
source bin/activate # for bash
```

3. Install dependencies
3. Install dependencies

```bash
pip3 install genkit
pip3 install genkit-plugin-google-genai
```
```bash
pip3 install genkit
pip3 install genkit-plugin-google-genai
```

Or create a `requirements.txt` file
Or create a `requirements.txt` file

```
genkit
genkit-plugin-google-genai
```
```
genkit
genkit-plugin-google-genai
```

and run:
and run:

```bash
pip3 install -r requirements.txt
```
```bash
pip3 install -r requirements.txt
```

4. Configure your model API key
4. Configure your model API key

The simplest way to get started is with Google AI Gemini API. Make sure it's
[available in your region](https://ai.google.dev/available_regions).
The simplest way to get started is with Google AI Gemini API. Make sure it's
[available in your region](https://ai.google.dev/available_regions).

[Generate an API key](https://aistudio.google.com/app/apikey) for the
Gemini API using Google AI Studio. Then, set the `GEMINI_API_KEY`
environment variable to your key:
[Generate an API key](https://aistudio.google.com/app/apikey) for the
Gemini API using Google AI Studio. Then, set the `GEMINI_API_KEY`
environment variable to your key:

```posix-terminal
export GEMINI_API_KEY=<your API key>
```
```posix-terminal
export GEMINI_API_KEY=<your API key>
```

5. Create `main.py` file:
5. Create `main.py` file:

```python
```python
import json
from pydantic import BaseModel, Field
from genkit.ai import Genkit
Expand Down Expand Up @@ -103,70 +103,70 @@ This guide shows you how to get started with Genkit in a Python app.
print(json.dumps(await generate_character('Goblorb'), indent=2))

ai.run_main(main())
```
```

6. Run your app. Genkit apps are just regular python application. Run them
however you normally run your app.
6. Run your app. Genkit apps are just regular python application. Run them
however you normally run your app.

```bash
python3 main.py
```
```bash
python3 main.py
```

7. Inspect your app with the Genkit Dev UI
7. Inspect your app with the Genkit Dev UI

See instructions for installing the Genkit CLI (which includes the Dev UI)
below.
See instructions for installing the Genkit CLI (which includes the Dev UI)
below.

To inspect your app with Genkit Dev UI run with `genkit start -- <app>`
command. E.g.:
To inspect your app with Genkit Dev UI run with `genkit start -- <app>`
command. E.g.:

```bash
genkit start -- python3 main.py
```
```bash
genkit start -- python3 main.py
```

The command will print the Dev UI URL. E.g.:
The command will print the Dev UI URL. E.g.:

```
Genkit Developer UI: http://localhost:4000
```
```
Genkit Developer UI: http://localhost:4000
```

## Install Genkit CLI

1. If you don't already have Node 20 or newer on your system, install it now.
1. If you don't already have Node 20 or newer on your system, install it now.

Recommendation: The [`nvm`](https://github.com/nvm-sh/nvm) and
[`nvm-windows`](https://github.com/coreybutler/nvm-windows) tools are a
convenient way to install specific versions of Node if it's not already
installed on your system. These tools install Node on a per-user basis, so
you don't need to make system-wide changes.
Recommendation: The [`nvm`](https://github.com/nvm-sh/nvm) and
[`nvm-windows`](https://github.com/coreybutler/nvm-windows) tools are a
convenient way to install specific versions of Node if it's not already
installed on your system. These tools install Node on a per-user basis, so
you don't need to make system-wide changes.

To install `nvm`:
To install `nvm`:

* {Linux, macOS, etc.}
=== "Linux, macOS, etc."

Run the following command:
Run the following command:

```posix-terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
```
```posix-terminal
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
```

* {Windows}
=== "Windows"

Download and run the installer as described in the [nvm-windows
docs](https://github.com/coreybutler/nvm-windows?tab=readme-ov-file#install-nvm-windows).
Download and run the installer as described in the [nvm-windows
docs](https://github.com/coreybutler/nvm-windows?tab=readme-ov-file#install-nvm-windows).

Then, to install Node and `npm`, open a new shell and run the following
command:
Then, to install Node and `npm`, open a new shell and run the following
command:

```posix-terminal
nvm install 20
```
```posix-terminal
nvm install 20
```

2. Install the Genkit CLI by running the following command:
2. Install the Genkit CLI by running the following command:

```posix-terminal
npm i -g genkit-cli
```
```posix-terminal
npm i -g genkit-cli
```

This command installs the Genkit CLI into your Node installation directory so
that it can be used outside of a Node project.
This command installs the Genkit CLI into your Node installation directory so
that it can be used outside of a Node project.
Loading