Skip to content

Commit

Permalink
Updated README.md and example
Browse files Browse the repository at this point in the history
  • Loading branch information
prasad89 committed Nov 6, 2024
1 parent c5f8bd9 commit 3eb7099
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +36,7 @@ package main

import (
"fmt"

"github.com/prasad89/golamify/pkg/golamify"
)

Expand All @@ -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
}
}
}
}
```

Expand Down
47 changes: 47 additions & 0 deletions examples/generate/main.go
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}

0 comments on commit 3eb7099

Please sign in to comment.