From 3eb7099f5b92d36fd0fd36aa0d216764234e3030 Mon Sep 17 00:00:00 2001 From: prasad89 Date: Wed, 6 Nov 2024 08:36:48 +0530 Subject: [PATCH] Updated README.md and example --- README.md | 36 +++++++++++++++++++++++++----- examples/generate/main.go | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 examples/generate/main.go diff --git a/README.md b/README.md index 028dab4..8904c45 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ The **GoLamify** Go package provides an easy way to integrate Go projects with **Ollama**. +## ✨ Features + +1. **Generate Responses from Ollama Models** – Easily generate responses using a variety of Ollama models. +2. **Default Response Streaming** – Real-time response streaming for immediate output. +3. **Full Parameter Support** – Customize model behavior with full API parameter support. +4. **No Model Pulling Needed** – Access models without manual pre-pulling. +5. **Clear Error Handling** – Simple, concise error handling for easy debugging. +6. **More** – Comming soon. + ## 🚀 Getting Started ### Installation @@ -27,6 +36,7 @@ package main import ( "fmt" + "github.com/prasad89/golamify/pkg/golamify" ) @@ -37,13 +47,29 @@ func main() { return } - resp, err := golamify.Generate(client, "llama3.2", "Why is the sky blue?") - if err != nil { - fmt.Println("Error generating response:", err) - return + payload := golamify.GeneratePayload{ + Model: "llama3.2:1b", + Prompt: "Why is the sky blue?", } - fmt.Println("Response:", resp.Response) + responseChannel, errorChannel := golamify.Generate(client, &payload) + + for { + select { + case response, ok := <-responseChannel: + if !ok { + return + } + fmt.Print(response["response"]) + + case err, ok := <-errorChannel: + if ok && err != nil { + fmt.Println("Error:", err) + } else if !ok { + return + } + } + } } ``` diff --git a/examples/generate/main.go b/examples/generate/main.go new file mode 100644 index 0000000..aba739b --- /dev/null +++ b/examples/generate/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "time" + + "github.com/prasad89/golamify/pkg/golamify" +) + +func main() { + // Optional config; pass nil for defaults + config := golamify.Config{ + OllamaHost: "http://localhost:11434", + Timeout: 30 * time.Second, + } + + client, err := golamify.NewClient(&config) + if err != nil { + fmt.Println("Error creating client:", err) + return + } + + // Required parameters for Generate; others optional + payload := golamify.GeneratePayload{ + Model: "llama3.2:1b", + Prompt: "Why is the sky blue?", + } + + responseChannel, errorChannel := golamify.Generate(client, &payload) + + for { + select { + case response, ok := <-responseChannel: + if !ok { + return + } + fmt.Print(response["response"]) + + case err, ok := <-errorChannel: + if ok && err != nil { + fmt.Println("Error:", err) + } else if !ok { + return + } + } + } +}