Skip to content

Commit

Permalink
docs: add Python and Go to most docs pages (#1014)
Browse files Browse the repository at this point in the history
* docs: add Python and Go to most docs pages

* docs: Python and Go examples

* docs: Flow Control code snippets in Go and Python

* docs: Inngest Tour for Python and Go

* docs: serving inngest functions in Go and Python

* docs: Python & Go DX

* docs: guides in Go and Python

* feat(docs): persist language selection across pages

* docs: Python & Go coverage fixes

* feat(docs): make `<CodeGroup>` compatible with `<GuideSelector>` persisted storage

* fix(docs): broken link
  • Loading branch information
charlypoly authored Dec 11, 2024
1 parent 46e52f5 commit a05739a
Show file tree
Hide file tree
Showing 41 changed files with 4,066 additions and 296 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@algolia/autocomplete-preset-algolia": "1.7.4",
"@babel/core": "7.20.12",
"@fullstory/browser": "1.6.2",
"@headlessui/react": "1.7.13",
"@headlessui/react": "1.7.19",
"@heroicons/react": "2.0.18",
"@mdx-js/loader": "2.2.1",
"@mdx-js/react": "2.2.1",
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/agent-kit/ai-agent-network-state-routing.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Callout, GuideSelector, GuideSection, CodeGroup } from "src/shared/Docs/mdx";
import { Callout, GuideSelector, GuideSection, CodeGroup, VersionBadge } from "src/shared/Docs/mdx";

# Networks, state, and routing
# Networks, state, and routing <VersionBadge version="TypeScript only" />

<Callout variant="info">
Use Networks to create complex workflows with one or more agents.
Expand Down
10 changes: 5 additions & 5 deletions pages/docs/agent-kit/ai-agents-tools.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Callout, GuideSelector, GuideSection, CodeGroup } from "src/shared/Docs/mdx";
import { Callout, GuideSelector, GuideSection, CodeGroup, VersionBadge } from "src/shared/Docs/mdx";

# Agents and Agent Tools
# Agents and Agent Tools <VersionBadge version="TypeScript only" />

<Callout variant="info">
You can think of an Agent as a wrapper over a single model, with instructions and tools. Calling `.run` on an Agent
Expand All @@ -20,7 +20,7 @@ Agents are the core of AgentKit. An Agent is used to call a single model with a
Here’s a simple agent, which makes a single model call using system prompts and user input:

```jsx
import { Agent, agenticOpenai as openai } from "@inngest/agent-kit";
import { Agent, agenticOpenai as openai, createAgent } from "@inngest/agent-kit";

const agent = createAgent({
name: "Code writer",
Expand Down Expand Up @@ -73,7 +73,7 @@ You can define an agent's system prompt as a string or as an async callback whic
Here's an example:

```ts
import { Agent, Network, agenticOpenai as openai } from "@inngest/agent-kit";
import { Agent, Network, agenticOpenai as openai, createAgent } from "@inngest/agent-kit";

const systemPrompt =
"You are an expert TypeScript programmer. Given a set of asks, think step-by-step to plan clean, " +
Expand Down Expand Up @@ -126,7 +126,7 @@ In AgentKit, you also define a `handler` function which is called when the tool
A more complex agent used in a network defines a description, lifecycle hooks, tools, and a dynamic set of instructions based off of network state:

```ts
import { Agent, Network, agenticOpenai as openai } from "@inngest/agent-kit";
import { Agent, Network, agenticOpenai as openai, createAgent } from "@inngest/agent-kit";

const systemPrompt =
"You are an expert TypeScript programmer. Given a set of asks, think step-by-step to plan clean, " +
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/agent-kit/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Callout, GuideSelector, GuideSection, CodeGroup } from "src/shared/Docs/mdx";
import { Callout, GuideSelector, GuideSection, CodeGroup, VersionBadge } from "src/shared/Docs/mdx";

# AgentKit overview
# AgentKit overview <VersionBadge version="TypeScript only" />

<Callout variant="info">
This page introduces the APIs and concepts to AgentKit. AgentKit is in early access, and is improving
Expand Down
96 changes: 93 additions & 3 deletions pages/docs/apps/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ The diagram below shows how each environment can have multiple apps which can ha

## Apps in SDK

Each [`serve()` API handler](/docs/reference/serve) will generate an app in Inngest upon syncing.
The app ID is determined by the ID passed to the serve handler from the [Inngest client](/docs/reference/client/create).
Each [`serve()` API handler](/docs/learn/serving-inngest-functions) will generate an app in Inngest upon syncing.
The app ID is determined by the ID passed to the serve handler from the Inngest client.

For example, the code below will create an Inngest app called “example-app” which contains one function:

<CodeGroup>
```ts
```ts {{ title: "Node.js" }}
import { Inngest } from "inngest";
import { serve } from "inngest/next"; // or your preferred framework
import { sendSignupEmail } from "./functions";
Expand All @@ -42,6 +42,96 @@ serve({
functions: [sendSignupEmail],
});
```

```python {{ title: "Python (Flask)" }}
import logging
import inngest
from src.flask import app
import inngest.flask

logger = logging.getLogger(f"{app.logger.name}.inngest")
logger.setLevel(logging.DEBUG)

inngest_client = inngest.Inngest(app_id="flask_example", logger=logger)

@inngest_client.create_function(
fn_id="hello-world",
trigger=inngest.TriggerEvent(event="say-hello"),
)
def hello(
ctx: inngest.Context,
step: inngest.StepSync,
) -> str:

inngest.flask.serve(
app,
inngest_client,
[hello],
)

app.run(port=8000)
```

```python {{ title: "Python (FastAPI)" }}
import logging
import inngest
import fastapi
import inngest.fast_api


logger = logging.getLogger("uvicorn.inngest")
logger.setLevel(logging.DEBUG)

inngest_client = inngest.Inngest(app_id="fast_api_example", logger=logger)

@inngest_client.create_function(
fn_id="hello-world",
trigger=inngest.TriggerEvent(event="say-hello"),
)
async def hello(
ctx: inngest.Context,
step: inngest.Step,
) -> str:
return "Hello world!"

app = fastapi.FastAPI()

inngest.fast_api.serve(
app,
inngest_client,
[hello],
)
```

```go {{ title: "Go (HTTP)" }}
package main

import (
"context"
"fmt"
"net/http"
"time"

"github.com/inngest/inngestgo"
"github.com/inngest/inngestgo/step"
)

func main() {
h := inngestgo.NewHandler("core", inngestgo.HandlerOpts{})
f := inngestgo.CreateFunction(
inngestgo.FunctionOpts{
ID: "account-created",
Name: "Account creation flow",
},
// Run on every api/account.created event.
inngestgo.EventTrigger("api/account.created", nil),
AccountCreated,
)
h.Register(f)
http.ListenAndServe(":8080", h)
}
```

</CodeGroup>

<Callout>
Expand Down
28 changes: 27 additions & 1 deletion pages/docs/dev-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,40 @@ There are different ways that you can send events to the dev server when testing

When using the Inngest SDK locally, it tries to detect if the dev server is running on your machine. If it's running, the event will be sent there.

```ts
<CodeGroup>
```ts {{ title: "Node.js" }}
import { Inngest } from "inngest";

const inngest = new Inngest({ id: "my-app" });
await inngest.send({
name: "user.avatar.uploaded",
data: { url: "https://a-bucket.s3.us-west-2.amazonaws.com/..." },
});
```

```python {{ title: "Python" }}
from inngest import Inngest

inngest_client = inngest.Inngest(app_id="my_app")
await inngest_client.send(
name="user.avatar.uploaded",
data={"url": "https://a-bucket.s3.us-west-2.amazonaws.com/..."},
)
```

```go {{ title: "Go" }}
package main

import "github.com/inngest/inngest-go"

func main() {
inngestgo.Send(context.Background(), inngestgo.Event{
Name: "user.avatar.uploaded",
Data: map[string]any{"url": "https://a-bucket.s3.us-west-2.amazonaws.com/..."},
})
}
```
</CodeGroup>
**Note** - During local development, you can use a dummy value for your [`INNGEST_EVENT_KEY`](/docs/sdk/environment-variables#inngest-event-key?ref=local-development) environment variable. The dev server does not validate keys locally.

#### Using the "Test Event" button
Expand Down
Loading

0 comments on commit a05739a

Please sign in to comment.