Skip to content

Tutorial 1: Your First Conversation

Build a chatbot in 5 lines of code using the PromptKit SDK.

  • Open a conversation from a pack file
  • Send messages and receive responses
  • Use template variables
  • Multi-turn conversations

Create a new Go module:

Terminal window
mkdir my-chatbot
cd my-chatbot
go mod init my-chatbot

Install the SDK:

Terminal window
go get github.com/AltairaLabs/PromptKit/sdk

Create hello.pack.json:

{
"id": "hello-chatbot",
"name": "Hello Chatbot",
"version": "1.0.0",
"template_engine": {
"version": "v1",
"syntax": "{{variable}}"
},
"prompts": {
"chat": {
"id": "chat",
"name": "Chat Assistant",
"version": "1.0.0",
"system_template": "You are a helpful AI assistant. Be concise and friendly. The user's name is {{user_name}}.",
"parameters": {
"temperature": 0.7,
"max_tokens": 1000
}
}
}
}

This pack defines your assistant’s behavior and configuration.

Create main.go:

package main
import (
"context"
"fmt"
"log"
"github.com/AltairaLabs/PromptKit/sdk"
)
func main() {
// Open a conversation from a pack file
conv, err := sdk.Open("./hello.pack.json", "chat")
if err != nil {
log.Fatal(err)
}
defer conv.Close()
// Set template variables (optional)
conv.SetVar("user_name", "World")
// Send a message and get a response
ctx := context.Background()
resp, err := conv.Send(ctx, "Hello!")
if err != nil {
log.Fatal(err)
}
// Print the response
fmt.Println(resp.Text())
}

That’s it! 5 lines of functional code (excluding error handling).

Set your API key:

Terminal window
export OPENAI_API_KEY="your-api-key-here"

Run the program:

Terminal window
go run main.go

You should see:

Hello World! How can I help you today?

🎉 Congratulations! You’ve built your first chatbot.

conv, err := sdk.Open("./hello.pack.json", "chat")
  • First argument: path to your pack file
  • Second argument: prompt name from the pack
  • Returns a Conversation ready to use
conv.SetVar("user_name", "World")

Sets template variables that are substituted into the system prompt.

resp, err := conv.Send(ctx, "Hello!")

Sends a message and returns the response. The conversation context is maintained automatically.

fmt.Println(resp.Text())

Gets the text content from the response.

The SDK automatically maintains conversation history:

// Turn 1
resp1, _ := conv.Send(ctx, "My name is Alice")
fmt.Println(resp1.Text()) // "Nice to meet you, Alice!"
// Turn 2 - context is remembered
resp2, _ := conv.Send(ctx, "What's my name?")
fmt.Println(resp2.Text()) // "Your name is Alice."
conv, err := sdk.Open("./hello.pack.json", "chat",
sdk.WithModel("gpt-4o"),
sdk.WithTemperature(0.9),
)

The pack file can specify different providers:

{
"id": "my-chatbot",
"name": "My Chatbot",
"version": "1.0.0",
"template_engine": {
"version": "v1",
"syntax": "{{variable}}"
},
"provider": {
"name": "anthropic",
"model": "claude-3-5-sonnet-20241022"
},
"prompts": {
"chat": {
"id": "chat",
"name": "Chat",
"version": "1.0.0",
"system_template": "You are a helpful assistant."
}
}
}

Make it interactive:

package main
import (
"bufio"
"context"
"fmt"
"log"
"os"
"strings"
"github.com/AltairaLabs/PromptKit/sdk"
)
func main() {
conv, err := sdk.Open("./hello.pack.json", "chat")
if err != nil {
log.Fatal(err)
}
defer conv.Close()
ctx := context.Background()
scanner := bufio.NewScanner(os.Stdin)
fmt.Println("Chat ready! Type 'quit' to exit.")
for {
fmt.Print("You: ")
if !scanner.Scan() {
break
}
msg := strings.TrimSpace(scanner.Text())
if msg == "quit" {
break
}
resp, err := conv.Send(ctx, msg)
if err != nil {
log.Printf("Error: %v", err)
continue
}
fmt.Printf("Assistant: %s\n\n", resp.Text())
}
}

✅ Open conversations with sdk.Open()
✅ Set template variables with SetVar()
✅ Send messages with Send()
✅ Multi-turn conversation context
✅ Configuration options

See the full example at sdk/examples/hello/.