Skip to content
Merged
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
paths:
- 'docs/**'

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
working-directory: docs

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: docs/package-lock.json

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/dist
force_orphan: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
commit_message: 'Deploy documentation to GitHub Pages'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ __pycache__/
.pytest_cache
**.egg-info
dist/
.venv/
node_modules/
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next/
.DS_Store
23 changes: 23 additions & 0 deletions docs/app/[[...mdxPath]]/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { generateStaticParamsFor, importPage } from 'nextra/pages'
import { useMDXComponents as getMDXComponents } from '../../mdx-components'

export const generateStaticParams = generateStaticParamsFor('mdxPath')

export async function generateMetadata(props) {
const params = await props.params
const { metadata } = await importPage(params.mdxPath)
return metadata
}

const Wrapper = getMDXComponents().wrapper

export default async function Page(props) {
const params = await props.params
const result = await importPage(params.mdxPath)
const { default: MDXContent, toc, metadata } = result
return (
<Wrapper toc={toc} metadata={metadata}>
<MDXContent {...props} params={params} />
</Wrapper>
)
}
47 changes: 47 additions & 0 deletions docs/app/layout.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Footer, Layout, Navbar } from 'nextra-theme-docs'
import { Banner, Head } from 'nextra/components'
import { getPageMap } from 'nextra/page-map'
import 'nextra-theme-docs/style.css'

export const metadata = {
// Define your metadata here
// For more information on metadata API, see: https://nextjs.org/docs/app/building-your-application/optimizing/metadata
}

const navbar = (
<Navbar
logo={<b>AI SDK - Python</b>}
// ... Your additional navbar options
/>
)
const footer = <Footer>MIT {new Date().getFullYear()} © jverre.</Footer>

export default async function RootLayout({ children }) {
return (
<html
// Not required, but good for SEO
lang="en"
// Required to be set
dir="ltr"
// Suggested by `next-themes` package https://github.com/pacocoursey/next-themes#with-app
suppressHydrationWarning
>
<Head
// ... Your additional head options
>
{/* Your additional tags should be passed as `children` of `<Head>` element */}
</Head>
<body>
<Layout
navbar={navbar}
pageMap={await getPageMap()}
docsRepositoryBase="https://github.com/jverre/ai-sdk/tree/main/docs"
footer={footer}
// ... Your additional layout options
>
{children}
</Layout>
</body>
</html>
)
}
15 changes: 15 additions & 0 deletions docs/content/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GitHubIcon } from 'nextra/icons'

export default {
index: {
title: 'AI SDK',
type: 'doc'
},
guides: 'Guides',
providers: 'Providers'
}

// Custom component for italicized text
function Italic({ children, ...props }) {
return <i {...props}>{children}</i>
}
6 changes: 6 additions & 0 deletions docs/content/guides/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
overview: 'Overview',
models: 'Models and Providers',
text_generation: 'Text Generation',
structured_outputs: 'Structured Outputs',
}
87 changes: 87 additions & 0 deletions docs/content/guides/models.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Tabs } from 'nextra/components'

# Models and Providers

The Python AI SDK allowss you to call many different LLM models through a unified interface which makes it easy
to switch between models.

The following providers are currently supported:

* [OpenAI](https://platform.openai.com/docs/guides/text)
* [Anthropic](https://docs.anthropic.com/en/docs/welcome)
* [OpenRouter](https://openrouter.ai/docs/quickstart)

## Using a model

In order to use a model from a specific provider, you will first need to import the provider and then initialize the model which
can then be used within the `generate_text` and `generate_object` functions.

<Tabs items={['OpenAI', 'Anthropic', 'OpenRouter']}>
<Tabs.Tab>
```python
from ai_sdk import generate_text
from ai_sdk.openai import openai

response = generate_text(
model=openai("gpt-4o"),
prompt="Hello, world!"
)

print(response.text)
```
</Tabs.Tab>
<Tabs.Tab>
```python
from ai_sdk import generate_text
from ai_sdk.anthropic import anthropic

response = generate_text(
model=anthropic("claude-3-5-sonnet-20240620"),
prompt="Hello, world!"
)

print(response.text)
```
</Tabs.Tab>
<Tabs.Tab>
```python
from ai_sdk import generate_text
from ai_sdk.openrouter import openrouter

response = generate_text(
model=openrouter("openai/gpt-4o"),
prompt="Hello, world!"
)

print(response.text)
```
</Tabs.Tab>
</Tabs>

## Advanced Usage

### Customizing provider settings

You can customize the provider settings by utilizing the `create_<Provider>_provider` function. This allows you to
pass in additional settings like API keys, base URLs, etc. For example, if you want to use the OpenAI provider with a
custom base URL, you can do the following:

```python
from ai_sdk.openai import create_openai_provider, OpenAIProviderSettings

provider = create_openai_provider(
settings=OpenAIProviderSettings(
base_url="https://api.openai.com",
api_key="your_api_key"
)
)

response = generate_text(
model=provider("gpt-4o"),
prompt="Hello, world!"
)

print(response.text)
```

For a full list of available settings for each provider, please refer to each provider's documentation.
62 changes: 62 additions & 0 deletions docs/content/guides/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Cards } from 'nextra/components'
import { FiMessageSquare, FiGrid, FiTool } from 'react-icons/fi'
import { Callout } from 'nextra/components'

# Overview

The AI SDK was heavily inspired by the [AI SDK](https://sdk.vercel.ai/) built by the Vercel team. This SDK is
a partial port of that JavaScript SDK to Python.

## Installation

```bash
pip install ai-sdk-python
```

## Usage

The AI SDK is designed to make it easy to work with different AI providers whether that is to generate text
or structured outputs. All you need to do is import the library and call the `generate_text` function to get
started:

```python
from ai_sdk import generate_text
from ai_sdk.openai import openai

response = generate_text(
model=openai("gpt-4o"),
prompt="Hello, world!"
)

print(response.text)
```

You can learn more about using the AI SDK in our guides:

<Cards>
<Cards.Card
icon={<FiMessageSquare />}
title="Prompts"
href="/guides/prompts"
arrow
/>
<Cards.Card
icon={<FiGrid />}
title="Structured Outputs"
href="/guides/structured-outputs"
arrow
/>
<Cards.Card
icon={<FiTool />}
title="Tools"
href="/guides/tools"
arrow
/>
</Cards>

You can also find a full list of all the providers we support
in the Providers section.

<Callout type="info">
If you would like us to support a new provider, please reach out to us on [Github](https://github.com/jverre/ai-sdk/issues).
</Callout>
Loading