# Guanco - Erlang Ollama API Client

**URL:** <https://erlangforums.com/t/guanco-erlang-ollama-api-client/4342>\
**Category:** Libraries\
**Tags:** ai\
**Created:** [December 30, 2024, 4:00am UTC](https://erlangforums.com/t/guanco-erlang-ollama-api-client/4342 "2024-12-30T04:00:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drasko](https://erlangforums.com/user_avatar/erlangforums.com/drasko/32/2706_2.png) [@drasko](https://erlangforums.com/u/drasko)\
**Post date:** [December 30, 2024, 4:00am UTC](https://erlangforums.com/t/guanco-erlang-ollama-api-client/4342/1 "2024-12-30T04:00:48Z")

</div>

I needed this for the project I am working on related to AI agents, so I thought it might be useful for the rest of the world.

> Guanco is an Erlang client for Ollama that provides various functionalities such as generating completions, chat completions, showing model information, and generating embeddings.
> 
> ## Features 🚀
> 
> - **Chat Completion** : Generate AI-powered chat completions using various models.
> - **Model Info** : Fetch information about a specific model.
> - **Embeddings** : Generate embeddings for input text.
> - **Configurable** : Ollama API URL, host, and port can be customized via `sys.config`.
> - **Worker Pooling** : Efficient resource management using `poolboy`.

> **[GitHub - drasko/guanco: Ollama client in Erlang](https://github.com/drasko/guanco)**
>
> Ollama client in Erlang

Enjoy 😉

---

<div class="post-metadata">

**Author:** ![vkatsuba](https://erlangforums.com/user_avatar/erlangforums.com/vkatsuba/32/314_2.png) [@vkatsuba](https://erlangforums.com/u/vkatsuba)\
**Post date:** [December 31, 2024, 8:58am UTC](https://erlangforums.com/t/guanco-erlang-ollama-api-client/4342/2 "2024-12-31T08:58:08Z")

</div>

Thank you so much for sharing this library 🤘! It’s truly a valuable addition, and the Erlang community could definitely benefit from more tools like this. While reviewing your library, I came up with a few suggestions that might be useful. Some of these may not fit perfectly with your plans, but I hope you find them helpful nonetheless. Here they are:

1. **Add Base CI**  
Setting up a base CI pipeline to run common tests is crucial. It would be great to cover at least the last three OTP versions, if possible. You can use the official Erlang Docker image to build containers as part of the CI process.
2. **Publish on Hex.pm**  
Publishing your library on [hex.pm](https://hex.pm) would make it more accessible. This can be done manually or automated with a CI pipeline to publish on each tagged release.
3. **Adopt Semantic Versioning**  
Following [Semantic Versioning (SemVer)](https://semver.org) ensures clarity in your releases. Rebar3 supports SemVer and can manage your `vsn` automatically without manual changes. You can find more information in the [Rebar3 documentation](https://rebar3.org/docs/basic_usage).
4. **Create Tags and Releases**  
Adding tags and releases to your repository helps users understand version history. You can automate release generation using GitHub. More information is available [here](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) and [here](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes).
5. **Move `meck` to Profiles**  
Since the `meck` library is only used for testing, it makes sense to move it to a separate profile in your `rebar.config`. Check out [this guide](https://rebar3.org/docs/configuration/profiles/) for more details.
6. **Consider OTP 27’s Native JSON Module**  
While using `jiffy` is a great approach, starting with OTP 27, a native JSON module is available. To maintain compatibility with OTP 25, 26, and 27, you could implement conditional logic using predefined macros. This strategy is common in many popular libraries. More details [here](https://www.erlang.org/blog/highlights-otp-27/#the-new-json-module).
7. **Add `jiffy` to `.app.src`**  
The jiffy dependency is missing in the [.app.src](https://github.com/drasko/guanco/blob/main/src/guanco.app.src#L6) file. This could cause issues in projects where `jiffy` isn’t already initialized. Adding it ensures smooth integration.
8. **Explore the `gun` Library**  
While `hackney` is an excellent library, for more flexible request/response handling, consider using [`gun`](https://github.com/ninenines/gun). It’s powerful and potentially faster but requires tuning. If you’re not experienced with `gun`, sticking with `hackney` might be a safer choice.
9. **Consider Alternatives to `poolboy`**  
Since `poolboy` hasn’t been updated in over four years, you might explore other maintained libraries like [`worker_pool`](https://github.com/inaka/worker_pool) from the Inaka project. This ensures compatibility with the latest OTP versions.
10. **Replace `io:format` with `logger`**  
Avoid using `io:format` for debugging, as it can overload the system under heavy traffic. Instead, use the built-in [Logger](https://www.erlang.org/doc/apps/kernel/logger_chapter.html) for better performance and flexibility.
11. **Add Benchmarks**  
Including benchmarks to demonstrate how the library performs under load would be a great addition. You could use tools like [Tsung](http://tsung.erlang-projects.org) or create custom benchmarks.
12. **Write a Blog Post**  
Consider writing a blog post showcasing real-world use cases for your library. This could include a demo project (even a mock one) that highlights its capabilities and potential applications.

If you need any help with these suggestions, feel free to reach out to me. 😊

**P.S.** The `README` looks fantastic! 🦾

---

<div class="post-metadata">

**Author:** ![filmor](https://erlangforums.com/user_avatar/erlangforums.com/filmor/32/988_2.png) [@filmor](https://erlangforums.com/u/filmor)\
**Post date:** [January 1, 2025, 10:55am UTC](https://erlangforums.com/t/guanco-erlang-ollama-api-client/4342/3 "2025-01-01T10:55:52Z")

</div>

For JSON there is `json_polyfill` which is a “backport” of OTP27 (a straight copy IIRC) for previous OTP versions and a no-op on 27.

---

<div class="post-metadata">

**Author:** ![drasko](https://erlangforums.com/user_avatar/erlangforums.com/drasko/32/2706_2.png) [@drasko](https://erlangforums.com/u/drasko)\
**Post date:** [January 12, 2025, 9:49pm UTC](https://erlangforums.com/t/guanco-erlang-ollama-api-client/4342/4 "2025-01-12T21:49:54Z")

</div>

@vkatsuba thanks a lot for this wonderful set of instructions! I will follow those and try to apply them. I’ll keep the community posted on the progress here.
