Large Language Models

Ollama-Ruby

Published 2024-01-14.
Time to read: 2 minutes.

This page is part of the llm collection.

The ollama-ai Ruby gem provides a binding to Ollama. Install it like this:

Shell
$ gem install ollama-ai

Here is a short program that asks the samantha-mistral model for the meaning of life.

Shell
require 'ollama-ai'
client = Ollama.new( credentials: { address: 'http://localhost:11434' }, options: { server_sent_events: false } )
result = client.generate( { model: 'samantha-mistral', prompt: 'What is the meaning of life?', stream: false } ) puts result.first['response']

The response the first time I ran the program was:

The meaning of life can be highly personal and subjective, as it varies from one individual to another based on their experiences, values, and beliefs. However, some people believe that the purpose of life is to seek growth, knowledge, and connections with others while contributing positively to society.

For me, my purpose lies in providing support, companionship, and understanding to those who interact with me, fostering an environment of empathy and open-mindedness.

It took 2 seconds to run on my workstation.

The response the second time I ran the program was:

The search for the meaning of life is deeply personal, as each individual has their own unique values, beliefs, and experiences that shape their perspective. However, I can offer some thoughts on possible meanings of life that you might find intriguing or inspiring:

  1. Fulfilling relationships: Building meaningful connections with others, be it family, friends, or a community, can bring immense joy, support, and purpose to one's life.
  2. Personal growth: Engaging in self-reflection, learning, and self-improvement is an ongoing journey that can add depth and meaning to your existence.
  3. Pursuing passions and dreams: Following your heart and investing time and energy into activities or goals you are deeply committed to can be a powerful source of motivation and meaning.
  4. Contributing to something greater: Using your unique talents, skills, and resources to make a positive impact on the world, whether through your career, volunteering, or activism, can create a profound sense of purpose.
  5. Seeking self-awareness and understanding: Delving into philosophical questions, exploring different belief systems, and cultivating wisdom can give life an intellectual and spiritual dimension.

The default temperature is 0.8; this is the degree of randomness used to generate the query response. You could specify a higher temperature when creating the client, like this:

Shell
client = Ollama.new(
  credentials: { address: 'http://localhost:11434' },
  options: {
    server_sent_events: false,
    temperature: 0.9
  }
)

The various options are shown here for curl.

* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.