This section provides detailed documentation for each of the services available in the go-tabbyapi client library.
- Completions Service: Generate text completions based on prompts
- Chat Service: Handle chat-based interactions with multi-role messages
- Embeddings Service: Generate vector embeddings from text inputs
- Models Service: Manage AI models (list, load, unload, etc.)
- Lora Service: Manage LoRA adapters for fine-tuning models
- Templates Service: Manage prompt templates for different model types
- Tokens Service: Handle token encoding and decoding operations
- Sampling Service: Manage sampling parameters for text generation
- Health Service: Check TabbyAPI server health status
- Auth Service: Manage authentication permissions
Each service is accessible through the main client interface:
// Create a client
client := tabby.NewClient(
tabby.WithBaseURL("http://localhost:8080"),
tabby.WithAPIKey("your-api-key"),
)
// Access a specific service
completionsService := client.Completions()
chatService := client.Chat()
modelsService := client.Models()
// ... and so on
Most service methods follow these common patterns:
-
Resource Creation:
resource, err := service.Create(ctx, request)
-
Resource Listing:
list, err := service.List(ctx)
-
Resource Retrieval:
resource, err := service.Get(ctx)
-
Resource Management:
err := service.Load(ctx, request) err := service.Unload(ctx)
-
Streaming Operations:
stream, err := service.CreateStream(ctx, request) defer stream.Close() for { chunk, err := stream.Recv() if err == io.EOF { break } if err != nil { return err } // Process chunk }
All service methods accept a context.Context
as their first parameter, which can be used for:
- Timeouts: Set deadlines for API requests
- Cancellation: Cancel in-progress requests
- Request scoping: Associate values with the request lifecycle
Example with timeout:
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
resp, err := client.Completions().Create(ctx, request)
Service methods return strongly typed errors that implement the tabby.Error
interface:
resp, err := client.Completions().Create(ctx, request)
if err != nil {
var apiErr *tabby.APIError
if errors.As(err, &apiErr) {
// Handle API-specific errors
log.Printf("API Error (Code: %s, Status: %d): %s",
apiErr.Code(), apiErr.HTTPStatusCode(), apiErr.Error())
} else {
// Handle other errors
log.Printf("Error: %v", err)
}
}