### Install gofabric client library Source: https://github.com/sherif-fanous/gofabric/blob/main/README.md Instructions to install the gofabric Go client library using the `go get` command. This command fetches the library and its dependencies. ```bash go get github.com/sherif-fanous/gofabric ``` -------------------------------- ### Initialize gofabric client with API key Source: https://github.com/sherif-fanous/gofabric/blob/main/README.md Demonstrates how to create a new gofabric client instance, specifying the Fabric API server host and an optional API key. It also includes an example of fetching the server configuration. ```Go package main import ( "context" "fmt" "log" "github.com/sherif-fanous/gofabric" ) func main() { // Replace with your Fabric API server host host := "http://localhost:8000" // Replace with your API key if required by the server apiKey := "your-api-key" client := gofabric.NewClient( host, gofabric.WithAPIKey(apiKey), ) // Example: Get server configuration config, err := client.GetConfig(context.Background()) if err != nil { log.Fatalf("Failed to get config: %v", err) } fmt.Printf("Fabric API Config: %+v\n", config) } ``` -------------------------------- ### Manage GoFabric Contexts: Create, List, Rename, Delete Source: https://github.com/sherif-fanous/gofabric/blob/main/README.md This Go example demonstrates how to perform various management operations on 'Context' entities using the `gofabric` client. It covers checking existence, creating a new context, listing all contexts, fetching context metadata, renaming an existing context, and finally deleting it. This code requires a running `gofabric` server and a valid API key for execution. ```go package main import ( "context" "fmt" "log" "strings" "github.com/sherif-fanous/gofabric" ) func main() { host := "http://localhost:8000" apiKey := "your-api-key" client := gofabric.NewClient( host, gofabric.WithAPIKey(apiKey), ) ctx := context.Background() contextName := "context_example.md" // Check if the context exists if ok, err := client.ContextExists(ctx, contextName); err != nil { log.Fatalf("Error checking context existence: %v\n", err) } else if ok { log.Printf("Context '%s' already exists\n", contextName) } else { log.Printf("Context '%s' does not exist, proceeding to create it\n", contextName) } // Create a new context err := client.CreateContext(ctx, contextName, strings.NewReader("Context content")) if err != nil { log.Fatalf("Error creating context: %v\n", err) } log.Printf("Context '%s' created successfully\n", contextName) // Check again if the context exists if ok, err := client.ContextExists(ctx, contextName); err != nil { log.Printf("Error checking context existence: %v\n", err) return } else if ok { log.Printf("Context '%s' already exists\n", contextName) } else { log.Printf("Context '%s' does not exist, proceeding to create it\n", contextName) } // List all contexts contexts, err := client.ListContexts(ctx) if err != nil { log.Fatalf("Error listing contexts: %v\n", err) } log.Printf("Available contexts: %v\n", contexts) // Fetch the context metadata contextMetadata, err := client.GetContextMetadata(ctx, contextName); if err != nil { log.Fatalf("Error fetching context metadata: %v\n", err) } log.Printf("Fetched context: %+v\n", contextMetadata) // Rename the context if err := client.RenameContext(ctx, contextName, "renamed_"+contextName); err != nil { log.Fatalf("Error renaming context: %v\n", err) } log.Printf("Context '%s' renamed to 'renamed_%s'\n", contextName, contextName) // Delete the context if err := client.DeleteContext(ctx, "renamed_"+contextName); err != nil { log.Fatalf("Error deleting context: %v\n", err) } log.Printf("Context 'renamed_%s' deleted successfully\n", contextName) } ``` -------------------------------- ### GoFabric API: Pattern and Session Management Methods Source: https://github.com/sherif-fanous/gofabric/blob/main/README.md This section outlines the available methods for managing 'Pattern' and 'Session' entities within the `gofabric` client, mirroring the functionality provided for 'Contexts'. These methods allow for creation, deletion, existence checks, metadata retrieval, listing, and renaming of patterns and sessions. ```APIDOC Pattern Management Methods: - CreatePattern(ctx, name, content) - DeletePattern(ctx, name) - PatternExists(ctx, name) - GetPatternMetadata(ctx, name) - ListPatterns(ctx) - RenamePattern(ctx, oldName, newName) Session Management Methods: - CreateSession(ctx, name, content) - DeleteSession(ctx, name) - SessionExists(ctx, name) - GetSessionMetadata(ctx, name) - ListSessions(ctx) - RenameSession(ctx, oldName, newName) ``` -------------------------------- ### Initiate streaming chat session with Fabric API Source: https://github.com/sherif-fanous/gofabric/blob/main/README.md Illustrates how to send a chat request to the Fabric API using the gofabric client. It shows how to construct a `ChatRequest` with prompts, vendor, model, and pattern, and then process streaming responses (content, error, complete) from the API. ```Go package main import ( "context" "fmt" "log" "github.com/sherif-fanous/gofabric" ) func main() { host := "http://localhost:8000" apiKey := "your-api-key" client := gofabric.NewClient( host, gofabric.WithAPIKey(apiKey), ) // Prepare chat request chatRequest := &gofabric.ChatRequest{ Prompts: []gofabric.PromptRequest{ { UserInput: "Write a Golang function that calculates the factorial of a number.", Vendor: "Gemini", Model: "gemini-2.0-flash", ContextName: "", PatternName: "coding_master", }, }, Language: "en", ChatOptions: gofabric.ChatOptions{}, } // Start streaming chat responses, err := client.Chat(context.Background(), chatRequest) if err != nil { log.Fatalf("Error sending chat request: %v", err) } for response := range responses { switch response.Type { case "content": log.Printf("Content (%s): %s\n", response.Format, response.Content) case "error": log.Printf("Error: %s\n", response.Content) case "complete": log.Printf("Chat completed") } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.