zoobzio December 13, 2025 Edit this page

Quickstart

Build your first LLM-powered feature in 10 minutes.

Installation

go get github.com/zoobz-io/zyn

Your First Synapse

Let's build an email classifier that categorizes incoming messages.

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/zoobz-io/zyn"
    "github.com/zoobz-io/zyn/openai"
)

func main() {
    // 1. Create a provider
    provider := openai.New(openai.Config{
        APIKey: os.Getenv("OPENAI_API_KEY"),
    })

    // 2. Create a classification synapse
    classifier, err := zyn.Classification(
        "What type of email is this?",
        []string{"spam", "urgent", "newsletter", "personal"},
        provider,
    )
    if err != nil {
        panic(err)
    }

    // 3. Create a session for context
    session := zyn.NewSession()

    // 4. Fire the synapse
    ctx := context.Background()
    category, err := classifier.Fire(ctx, session, "URGENT: Your account will be suspended!")
    if err != nil {
        panic(err)
    }

    fmt.Println("Category:", category) // "urgent"
}

What Just Happened?

  1. Provider - Connects to OpenAI's API
  2. Synapse - Defines the task (classify into categories)
  3. Session - Manages conversation context
  4. Fire - Executes the LLM call and returns typed results

Add Reliability

Real applications need error handling. Add retry and timeout:

classifier, err := zyn.Classification(
    "What type of email is this?",
    []string{"spam", "urgent", "newsletter", "personal"},
    provider,
    zyn.WithRetry(3),                    // Retry up to 3 times
    zyn.WithTimeout(10*time.Second),     // 10 second timeout
)

Try Different Synapses

Binary Decision

validator, _ := zyn.Binary("Is this a valid email address?", provider)
isValid, _ := validator.Fire(ctx, session, "user@example.com")
// isValid = true

Text Transformation

translator, _ := zyn.Transform("Translate to Spanish", provider)
spanish, _ := translator.Fire(ctx, session, "Hello, how are you?")
// spanish = "Hola, ¿cómo estás?"

Data Extraction

type Contact struct {
    Name  string `json:"name"`
    Email string `json:"email"`
}

func (c Contact) Validate() error {
    if c.Email == "" {
        return fmt.Errorf("email required")
    }
    return nil
}

extractor, _ := zyn.Extract[Contact]("contact information", provider)
contact, _ := extractor.Fire(ctx, session, "John Doe at john@example.com")
// contact = Contact{Name: "John Doe", Email: "john@example.com"}

Next Steps