Skip to content
coderPublic

About

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

Topics

Resources

Code of conduct

Security policy

Stars

41 stars

Watchers

4 watching

Forks

Repository files navigation

aisdk-go

GitHub Release GoDoc CI Status

Warning

This library is super new and may change a lot.

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

  • Supports OpenAI, Google, and Anthropic (with Bedrock support)
  • Examples for integrating useChat
  • Chain tool usage in Go, just like maxSteps
// frontend.tsx

const { messages } = useChat({
    // Points to our Go backend!
    api: "/api/chat",
})
// 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:

# any or all of these can be set
export OPENAI_API_KEY=<api-key>
export ANTHROPIC_API_KEY=<api-key>
export GOOGLE_API_KEY=<api-key>

cd demo
bun i
bun dev

About

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

Topics

Resources

Code of conduct

Security policy

Stars

41 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages