{"id":15394207,"url":"https://github.com/xyproto/ollamaclient","last_synced_at":"2025-07-15T06:42:28.568Z","repository":{"id":200707228,"uuid":"706116103","full_name":"xyproto/ollamaclient","owner":"xyproto","description":"Go package and example utilities for using Ollama / LLMs","archived":false,"fork":false,"pushed_at":"2025-01-28T15:34:38.000Z","size":3196,"stargazers_count":27,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T03:02:19.345Z","etag":null,"topics":["ai","fortune","go","image-description-generator","large-language-models","llamacpp","llm","ollama","ollama-client","summarize"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xyproto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-17T10:34:45.000Z","updated_at":"2025-03-28T10:08:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"da21c240-2caf-4c9a-a571-7e5f677edb9f","html_url":"https://github.com/xyproto/ollamaclient","commit_stats":{"total_commits":161,"total_committers":3,"mean_commits":"53.666666666666664","dds":"0.15527950310559002","last_synced_commit":"72442e9520aeff0faa4dd245da43652c2df3b742"},"previous_names":["xyproto/ollamaclient"],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Follamaclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Follamaclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Follamaclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xyproto%2Follamaclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xyproto","download_url":"https://codeload.github.com/xyproto/ollamaclient/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173061,"owners_count":21224481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","fortune","go","image-description-generator","large-language-models","llamacpp","llm","ollama","ollama-client","summarize"],"created_at":"2024-10-01T15:22:23.505Z","updated_at":"2025-07-15T06:42:28.553Z","avatar_url":"https://github.com/xyproto.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ollamaclient\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/xyproto/ollamaclient.svg)](https://pkg.go.dev/github.com/xyproto/ollamaclient/v2)\n\nA Go package for using Ollama and large language models (LLMs).\n\n### Example use\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/xyproto/ollamaclient/v2\"\n    \"github.com/xyproto/usermodel\"\n)\n\nfunc main() {\n    oc := ollamaclient.New(usermodel.GetTextGenerationModel())\n    oc.Verbose = true\n    if err := oc.PullIfNeeded(); err != nil {\n        fmt.Println(\"Error:\", err)\n        return\n    }\n    prompt := \"Write a haiku about the color of cows.\"\n    output, err := oc.GetOutput(prompt)\n    if err != nil {\n        fmt.Println(\"Error:\", err)\n        return\n    }\n    fmt.Printf(\"\\n%s\\n\", output)\n}\n```\n\nExample output (with verbosity set to `true`):\n\n```\nSending request to http://localhost:11434/api/tags\nSending request to http://localhost:11434/api/generate: {\"model\":\"gemma2:2b\",\"prompt\":\"Write a haiku about the color of cows.\",\"options\":{\"seed\":256,\"tempera}\n\nBrown hides, gentle eyes,\nMooing low in grassy fields,\nMilk flows, life's sweet hue.\n```\n\nMake sure to install and run Ollama locally first, or set `OLLAMA_HOST` to a valid host.\n\n### Using images in the prompt, with the `llava` model\n\nA simple way to describe images:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log\"\n\n    \"github.com/xyproto/ollamaclient/v2\"\n    \"github.com/xyproto/usermodel\"\n)\n\nfunc main() {\n    model := usermodel.GetVisionModel()\n    oc := ollamaclient.New(model)\n    oc.SetReproducible()\n    if err := oc.PullIfNeeded(true); err != nil {\n        log.Fatalln(err)\n    }\n    imageFilenames := []string{\"carrot1.png\", \"carrot2.png\"}\n    const desiredWordCount = 7\n    description, err := oc.DescribeImages(imageFilenames, desiredWordCount)\n    if err != nil {\n        log.Fatalln(err)\n    }\n    fmt.Println(description)\n}\n```\n\nSee `v2/cmd/describeimage` for an example that uses a custom prompt.\n\n### Embeddings\n\n* The `.Embeddings` method can be used to pass in a prompt and return a `[]float64`.\n\n### Environment variables\n\nThese environment variables are supported:\n\n* `OLLAMA_HOST` (`http://localhost:11434` by default)\n* `OLLAMA_MODEL` (uses the model defined by [`llm-manager`](https://github.com/xyproto/llm-manager) by default)\n* `OLLAMA_VERBOSE` (`false` by default)\n\n### The `summarize` utility\n\nGetting started:\n\n1. Install `ollama` and start it as a service.\n2. Install the `summarize` utility: `go install github.com/xyproto/ollamaclient/cmd/summarize@latest`\n3. Summarize a README.md file and a source code file: `summarize README.md ollamaclient.go`. This will also download the model if it's the first run.\n4. Write a poem about one or more files: `summarize --prompt \"Write a poem about the following files:\" README.md`\n\nUsage:\n\n```bash\n./summarize [flags] \u003cfilename1\u003e [\u003cfilename2\u003e ...]\n```\n\nFlags:\n\n- `-m`, `--model`: Specify an Ollama model.\n- `-o`, `--output`: Define an output file to store the summary.\n- `-p`, `--prompt`: Specify a custom prompt header for summary. The default is `Write a short summary of a project that contains the following files:`\n- `-w`, `--wrap`: Set the word wrap width. Use -1 to detect the terminal width.\n- `-v`, `--version`: Display the current version.\n- `-V`, `--verbose`: Enable verbose logging.\n\nGenerate a summary with a custom prompt:\n\n```bash\n./summarize -w -1 -p \"Summarize these files:\" README.md CONFIG.md\n```\n\nGenerate a summary, saving the output to a file:\n\n```bash\n./summarize -o output.txt README.md CONFIG.md\n```\n\nGenerate a summary with custom word wrap width:\n\n```bash\n./summarize -w 100 README.md\n```\n\n### Testing\n\n`go test` depends on a local Ollama server being up and running, and will attempt to download and use various models.\n\n### General info\n\n* Version: 2.7.1\n* License: Apache 2\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Follamaclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxyproto%2Follamaclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxyproto%2Follamaclient/lists"}