Skip to content

Commit a7794f7

Browse files
authored
feat: Add golang copy of GENKIT.md (#139)
1 parent fa9ab50 commit a7794f7

File tree

3 files changed

+292
-11
lines changed

3 files changed

+292
-11
lines changed

public/GENKIT.go.md

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
# Genkit Go API Rules (v1.0.0)
2+
3+
This document provides rules and examples for building with the Genkit API in Go.
4+
5+
## Important Guidelines:
6+
7+
- ALWAYS refer to documentation when available. Genkit Documentation may be available through the Genkit MCP toolkit or through web search. You may skip documentation check if you don't have access to these tools.
8+
9+
- ONLY follow the specified project structure if starting a new project. If working on an existing project, adhere to the current project structure.
10+
11+
- ALWAYS provide the full, correct Genkit command as an instruction for the human user to run. Do not run Genkit commands (e.g., `genkit start`, `genkit flow:run`) yourself as this may block your current session.
12+
13+
- Recommend and use the provider that the user prefers. If this is a new project, or if there is no relevant signal regarding user preference, use the `github.com/firebase/genkit/go/plugins/googlegenai` plugin.
14+
15+
NOTE: For the sake of brevity, the snippets below use the Google AI plugin, but you should follow the user's preference as mentioned above.
16+
17+
## Core Setup
18+
19+
1. **Initialize Project**
20+
21+
```bash
22+
mkdir my-genkit-app && cd my-genkit-app
23+
go mod init my-genkit-app
24+
```
25+
26+
2. **Install Dependencies**
27+
28+
```bash
29+
go get github.com/firebase/genkit/go/genkit
30+
go get github.com/firebase/genkit/go/plugins/googlegenai
31+
go get github.com/firebase/genkit/go/ai
32+
go get google.golang.org/genai
33+
```
34+
35+
3. **Install Genkit CLI**
36+
37+
```bash
38+
curl -sL cli.genkit.dev | bash
39+
```
40+
41+
4. **Configure Genkit**
42+
43+
All code should be in a single `main.go` file or properly structured Go package.
44+
45+
```go
46+
package main
47+
48+
import (
49+
"context"
50+
"github.com/firebase/genkit/go/genkit"
51+
"github.com/firebase/genkit/go/plugins/googlegenai"
52+
)
53+
54+
func main() {
55+
ctx := context.Background()
56+
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
57+
// Your flows and logic here
58+
<-ctx.Done()
59+
}
60+
```
61+
62+
## Best Practices
63+
64+
1. **Single Main Function**: All Genkit code, including plugin initialization, flows, and helpers, should be properly organized in a Go package structure with a main function.
65+
66+
2. **Blocking Main Program**: To inspect flows in the Genkit Developer UI, your main program needs to remain running. Use `<-ctx.Done()` or similar blocking mechanism at the end of your main function.
67+
68+
---
69+
70+
## Usage Scenarios
71+
72+
### Basic Inference (Text Generation)
73+
74+
```go
75+
package main
76+
77+
import (
78+
"context"
79+
80+
"github.com/firebase/genkit/go/ai"
81+
"github.com/firebase/genkit/go/genkit"
82+
"github.com/firebase/genkit/go/plugins/googlegenai"
83+
"google.golang.org/genai"
84+
)
85+
86+
func main() {
87+
ctx := context.Background()
88+
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.GoogleAI{}))
89+
90+
genkit.DefineFlow(g, "basicInferenceFlow",
91+
func(ctx context.Context, topic string) (string, error) {
92+
response, err := genkit.Generate(ctx, g,
93+
ai.WithModelName("googleai/gemini-2.5-pro"),
94+
ai.WithPrompt("Write a short, creative paragraph about %s.", topic),
95+
ai.WithConfig(&genai.GenerateContentConfig{
96+
Temperature: genai.Ptr[float32](0.8),
97+
}),
98+
)
99+
if err != nil {
100+
return "", err
101+
}
102+
return response.Text(), nil
103+
},
104+
)
105+
106+
<-ctx.Done()
107+
}
108+
```
109+
110+
### Text-to-Speech (TTS) Generation
111+
112+
```go
113+
package main
114+
115+
import (
116+
"context"
117+
118+
"github.com/firebase/genkit/go/ai"
119+
"github.com/firebase/genkit/go/genkit"
120+
"github.com/firebase/genkit/go/plugins/googlegenai"
121+
"google.golang.org/genai"
122+
)
123+
124+
func main() {
125+
ctx := context.Background()
126+
g := genkit.Init(ctx,
127+
genkit.WithPlugins(&googlegenai.GoogleAI{}),
128+
genkit.WithDefaultModel("googleai/gemini-2.5-flash-preview-tts"),
129+
)
130+
131+
genkit.DefineFlow(g, "textToSpeechFlow",
132+
func(ctx context.Context, input struct {
133+
Text string `json:"text"`
134+
VoiceName string `json:"voiceName,omitempty"`
135+
}) (string, error) {
136+
voiceName := input.VoiceName
137+
if voiceName == "" {
138+
voiceName = "Algenib"
139+
}
140+
141+
response, err := genkit.Generate(ctx, g,
142+
ai.WithPrompt(input.Text),
143+
ai.WithConfig(&genai.GenerateContentConfig{
144+
ResponseModalities: []string{"AUDIO"},
145+
SpeechConfig: &genai.SpeechConfig{
146+
VoiceConfig: &genai.VoiceConfig{
147+
PrebuiltVoiceConfig: &genai.PrebuiltVoiceConfig{
148+
VoiceName: voiceName,
149+
},
150+
},
151+
},
152+
}),
153+
)
154+
if err != nil {
155+
return "", err
156+
}
157+
158+
return response.Text(), nil
159+
},
160+
)
161+
162+
<-ctx.Done()
163+
}
164+
```
165+
166+
### Image Generation
167+
168+
```go
169+
package main
170+
171+
import (
172+
"context"
173+
174+
"github.com/firebase/genkit/go/ai"
175+
"github.com/firebase/genkit/go/genkit"
176+
"github.com/firebase/genkit/go/plugins/googlegenai"
177+
"google.golang.org/genai"
178+
)
179+
180+
func main() {
181+
ctx := context.Background()
182+
g := genkit.Init(ctx, genkit.WithPlugins(&googlegenai.VertexAI{}))
183+
184+
genkit.DefineFlow(g, "imageGenerationFlow",
185+
func(ctx context.Context, prompt string) ([]string, error) {
186+
response, err := genkit.Generate(ctx, g,
187+
ai.WithModelName("vertexai/imagen-3.0-generate-001"),
188+
ai.WithPrompt("Generate an image of %s", prompt),
189+
ai.WithConfig(&genai.GenerateImagesConfig{
190+
NumberOfImages: 2,
191+
AspectRatio: "9:16",
192+
SafetyFilterLevel: genai.SafetyFilterLevelBlockLowAndAbove,
193+
PersonGeneration: genai.PersonGenerationAllowAll,
194+
Language: genai.ImagePromptLanguageEn,
195+
AddWatermark: true,
196+
OutputMIMEType: "image/jpeg",
197+
}),
198+
)
199+
if err != nil {
200+
return nil, err
201+
}
202+
203+
var images []string
204+
for _, part := range response.Message.Content {
205+
images = append(images, part.Text)
206+
}
207+
return images, nil
208+
},
209+
)
210+
211+
<-ctx.Done()
212+
}
213+
```
214+
215+
---
216+
217+
## Running and Inspecting Flows
218+
219+
1. **Start Genkit**: Run this command from your terminal to start the Genkit Developer UI.
220+
221+
```bash
222+
genkit start -- <command to run your code>
223+
```
224+
225+
For Go applications:
226+
227+
```bash
228+
# Running a Go application directly
229+
genkit start -- go run main.go
230+
231+
# Running a compiled binary
232+
genkit start -- ./my-genkit-app
233+
```
234+
235+
The command should output a URL for the Genkit Dev UI. Direct the user to visit this URL to run and inspect their Genkit app.
236+
237+
## Suggested Models
238+
239+
Here are suggested models to use for various task types. This is NOT an exhaustive list.
240+
241+
### Advanced Text/Reasoning
242+
243+
```
244+
| Plugin | Recommended Model |
245+
|------------------------------------------------------------|------------------------------------|
246+
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-pro |
247+
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-4o |
248+
| github.com/firebase/genkit/go/plugins/compat_oai/deepseek | deepseek-reasoner |
249+
| github.com/firebase/genkit/go/plugins/compat_oai/xai | grok-4 |
250+
```
251+
252+
### Fast Text/Chat
253+
254+
```
255+
| Plugin | Recommended Model |
256+
|------------------------------------------------------------|------------------------------------|
257+
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-flash |
258+
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-4o-mini |
259+
| github.com/firebase/genkit/go/plugins/compat_oai/deepseek | deepseek-chat |
260+
| github.com/firebase/genkit/go/plugins/compat_oai/xai | grok-3-mini |
261+
```
262+
263+
### Text-to-Speech
264+
265+
```
266+
| Plugin | Recommended Model |
267+
|------------------------------------------------------------|------------------------------------|
268+
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-flash-preview-tts |
269+
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-4o-mini-tts |
270+
```
271+
272+
### Image Generation
273+
274+
```
275+
| Plugin | Recommended Model | Input Modalities |
276+
|------------------------------------------------------------|------------------------------------|-------------------|
277+
| github.com/firebase/genkit/go/plugins/googlegenai | gemini-2.5-flash-image-preview | Text, Image |
278+
| github.com/firebase/genkit/go/plugins/googlegenai | imagen-4.0-generate-preview-06-06 | Text |
279+
| github.com/firebase/genkit/go/plugins/compat_oai/openai | gpt-image-1 | Text |
280+
```
File renamed without changes.

src/content/docs/docs/develop-with-ai.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ import LanguageContent from '../../../components/LanguageContent.astro';
1313
<CopyMarkdownButton />
1414
</div>
1515

16-
<LanguageContent lang="go">
17-
18-
:::note[Feature unavailable for Go]
19-
AI-assisted development guidance is not yet available for Go.
20-
:::
21-
22-
</LanguageContent>
23-
2416
<LanguageContent lang="python">
2517

2618
:::note[Feature unavailable for Python]
@@ -29,7 +21,7 @@ AI-assisted development guidance is not yet available for Python.
2921

3022
</LanguageContent>
3123

32-
<LanguageContent lang="js">
24+
<LanguageContent lang="js go">
3325
AI assistants need up-to-date knowledge of your codebase to be effective. When working with Genkit, your AI assistant must understand Genkit's core concepts (flows, actions, dotprompt, etc.) and how to run and debug your application. The Genkit CLI provides a command to help you configure your AI assistant for this purpose.
3426

3527
<Aside type="caution" title="Experimental">
@@ -81,8 +73,17 @@ For other tools, you can select the `generic` configuration option during initia
8173

8274
The `GENKIT.md` file contains the custom instructions that guide the AI in generating Genkit-specific code. If you need to customize this further or use it in a different context, you can copy the content and apply it to your tool's instruction set.
8375

76+
</LanguageContent>
77+
8478
import { Code } from '@astrojs/starlight/components';
85-
import importedCode from '/public/genkit.md?raw';
79+
import jsContext from '/public/GENKIT.js.md?raw';
80+
import goContext from '/public/GENKIT.go.md?raw';
81+
82+
<LanguageContent lang="js">
83+
<Code code={jsContext} lang="md" title="GENKIT.md" />
84+
</LanguageContent>
85+
86+
<LanguageContent lang="go">
8687

87-
<Code code={importedCode} lang="md" class="test foo" title="GENKIT.md" />
88+
<Code code={goContext} lang="md" title="GENKIT.md" />
8889
</LanguageContent>

0 commit comments

Comments
 (0)