An open API service indexing awesome lists of open source software.

https://github.com/coder/aisdk-go

A Go implementation of Vercel's AI SDK Data Stream Protocol.
https://github.com/coder/aisdk-go

ai go sdk vercel

Last synced: 7 months ago
JSON representation

A Go implementation of Vercel's AI SDK Data Stream Protocol.

Awesome Lists containing this project

README

          

# aisdk-go

[![GitHub Release](https://img.shields.io/github/v/release/coder/aisdk-go?color=6b9ded&sort=semver)](https://github.com/coder/aisdk-go/releases)
[![GoDoc](https://godoc.org/github.com/coder/aisdk-go?status.svg)](https://godoc.org/github.com/coder/aisdk-go)
[![CI Status](https://github.com/coder/aisdk-go/workflows/ci/badge.svg)](https://github.com/coder/aisdk-go/actions)

> [!WARNING]
> This library is super new and may change a lot.

A Go implementation of Vercel's AI SDK [Data Stream Protocol](https://sdk.vercel.ai/docs/ai-sdk-ui/stream-protocol#data-stream-example).

- Supports OpenAI, Google, and Anthropic (with Bedrock support)
- Examples for integrating `useChat`
- Chain tool usage in Go, just like `maxSteps`

```ts
// frontend.tsx

const { messages } = useChat({
// Points to our Go backend!
api: "/api/chat",
})
```

```go
// backend.go

// Accept the POST request...
var req *aisdk.Chat

messages, err := aisdk.MessagesToOpenAI(req.Messages)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

// Convert the http.ResponseWriter to a Data Stream.
dataStream := aisdk.NewDataStream(w)
stream := openaiClient.Chat.Completions.NewStreaming(...)

aisdk.PipeOpenAIToDataStream(stream, dataStream)
```

## Development

Run tests with `go test`. Start the `useChat` demo with:

```bash
# any or all of these can be set
export OPENAI_API_KEY=
export ANTHROPIC_API_KEY=
export GOOGLE_API_KEY=

cd demo
bun i
bun dev
```