Skip to content

coder/aisdk-go

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

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages