Skip to main content

Tasks related to ollama

Project description

Zrb Ollama

Zrb Ollama is a pypi package that acts as Ollama's wrapper, allowing you to incorporate LLM into your workflow.

Installation

You can install Zrb Ollama by invoking the following command:

# From pypi
pip install zrb-ollama
# From github
pip install git+https://github.com/goFrendiAsgard/zrb-ollama.git@main
# From directory
pip install --use-feature=in-tree-build path/to/this/directory

Installing Ollama

You can install Ollama by visiting the official website: https://ollama.ai/.

Talk to Zrb Ollama

Once you install Zrb Ollama, you can then run it by invoking the following command:

zrb-ollama "Why is the sky blue?"
See the result:
 The sky appears blue during the day because of the scattering of sunlight by the Earth's atmosphere. When sunlight enters the Earth's atmosphere, it is scattered in all directions by molecules such as oxygen and nitrogen. Blue light has a shorter wavelength and scatters more easily than other colors, so it is scattered more widely across the sky, making it appear blue. This phenomenon is known as Rayleigh scattering.
 Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-12-31 10:42:03.249 โ  49899 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Completed in 24.471537828445435 seconds
 The sky appears blue during the day because of the scattering of sunlight by the Earth's atmosphere. When sunlight enters the Earth's atmosphere, it is scattered in all directions by molecules such as oxygen and nitrogen. Blue light has a shorter wavelength and scatters more easily than other colors, so it is scattered more widely across the sky, making it appear blue. This phenomenon is known as Rayleigh scattering.

 The color of the sky appears blue due to a natural phenomenon called Rayleigh scattering. As sunlight reaches Earth's atmosphere, it interacts with different gases and particles in the air. Blue light has a shorter wavelength and gets scattered more easily than other colors, such as red or yellow. This scattering scatters the blue light in all directions, making the sky appear blue during a clear day. However, at sunrise and sunset, the sky can display various shades of red, orange, and pink due to the presence of dust, pollutants, and water droplets in the atmosphere that scatter longer wavelengths (red and yellow) more effectively.Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-12-31 10:31:39.541 โ  45446 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Completed in 72.80772066116333 seconds
 The color of the sky appears blue due to a natural phenomenon called Rayleigh scattering. As sunlight reaches Earth's atmosphere, it interacts with different gases and particles in the air. Blue light has a shorter wavelength and gets scattered more easily than other colors, such as red or yellow. This scattering scatters the blue light in all directions, making the sky appear blue during a clear day. However, at sunrise and sunset, the sky can display various shades of red, orange, and pink due to the presence of dust, pollutants, and water droplets in the atmosphere that scatter longer wavelengths (red and yellow) more effectively.
 The sky appears blue because of a process called scattering. When sunlight enters the Earth's atmosphere, it collides with molecules such as oxygen and nitrogen dioxide, which scatter the light in all directions. Blue light has a shorter wavelength and is scattered more easily than other colors, so it is more visible to our eyes and therefore appears blue in the sky.Support zrb growth and development!

Zrb Ollama will save your context history in ~/.zrb-ollama-context.json. Thus, you can continue the conversation and retain the context

zrb-ollama "Explain in more detail"
See the result:
 Sure, I'd be happy to explain in more detail!

    When sunlight enters the Earth's atmosphere, it is scattered in all directions by molecules such as oxygen and nitrogen. Blue light has a shorter wavelength and scatters more easily than other colors, so it is scattered more widely across the sky. This means that when we look up at the sky during the day, we see a lot of blue light scattered in different directions.

    This phenomenon is known as Rayleigh scattering, named after British scientist Lord Rayleigh who discovered it in 1904. The amount and direction of scattering depends on several factors, including the wavelength of the light (which determines how much it scatters),
 the temperature of the air (which affects how much water vapor is present), and the altitude of the sun in the sky (which determines where the light has to travel through the atmosphere before reaching our eyes).

    So, when we see a blue sky during the day, we can thank Rayleigh scattering for making it appear that way.
Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-12-31 10:43:10.450 โ  50315 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Completed in 56.23700976371765 seconds
 Sure, I'd be happy to explain in more detail!

When sunlight enters the Earth's atmosphere, it is scattered in all directions by molecules such as oxygen and nitrogen. Blue light has a shorter wavelength and scatters more easily than other colors, so it is scattered more widely across the sky. This means that when we look up at the sky during the day, we see a lot of blue light scattered in different directions.

This phenomenon is known as Rayleigh scattering, named after British scientist Lord Rayleigh who discovered it in 1904. The amount and direction of scattering depends on several factors, including the wavelength of the light (which determines how much it scatters), the temperature of the air (which affects how much water vapor is present), and the altitude of the sun in the sky (which determines where the light has to travel through the atmosphere before reaching our eyes).

Talk is Cheap, Show Me The Code

Zrb Ollama can help you generate and run Python code.

zrb-ollama-py "x^2 + 5x + 3 = 0, find x"
See the result:
๐Ÿค– โ—‹ โ—ท 2023-12-28 07:30:38.357 โ  47317 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Context file: /home/gofrendi/.zrb-ollama-context.json
๐Ÿค– โ—‹ โ—ท 2023-12-28 07:30:38.357 โ  47317 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Sending request...
๐Ÿค– โ—‹ โ—ท 2023-12-28 07:32:41.068 โ  47317 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Waiting for response...
    Here's the Python code snippet that uses the quadratic formula to find the solutions for the given equation:

    ```python
    import cmath

    # coefficients
    a = 1
    b = 5
    c = 3

    # calculate discriminant
    discriminant = (b ** 2) - (4 * a * c)

    # find two solutions
    sol1 = (-b + cmath.sqrt(discriminant)) / (2 * a) if discriminant >= 0 else None
    sol2 = (-b - cmath.sqrt(-discriminant)) / (2 * a) if discriminant >= 0 else None

    print("Solutions for x:")
    if sol1 is not None:
        print(f"x1 = {sol1.real} + {sol1.imag}j")
    if sol2 is not None:
        print(f"x2 = {sol2.real} + {sol2.imag}j")
    ```

    This code imports the `cmath` library, which provides complex number support since the quadratic formula can result in complex solutions. The coefficients are defined, and then the discriminant is calculated using the given equation's coefficients. Finally, the two solutions for x are found, and their real and imaginary parts (if applicable) are printed out. If the discriminant is negative, there are no real solutions.
๐Ÿค– โ—‹ โ—ท 2023-12-28 07:34:36.751 โ  47317 โ†’ 1/3 ๐Ÿฆ™              prompt โ€ข Response completed
๐Ÿค– โ—‹ โ—ท 2023-12-28 07:34:36.752 โ  47317 โ†’ 1/1 โœ๏ธ           evaluate โ€ข Waiting for evaluation...
Solutions for x:
x1 = -0.6972243622680054 + 0.0j
x2 = -2.5 + -1.8027756377319946j
Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-12-28 07:34:36.765 โ  47317 โ†’ 1/1 โœ๏ธ           evaluate โ€ข Completed in 238.40946054458618 seconds
Solutions for x:
x1 = -0.6972243622680054 + 0.0j
x2 = -2.5 + -1.8027756377319946j

Creating a PromptTask

You can also import zrb-ollama into your Zrb project and perform some fun things:

from zrb import runner
from zrb_ollama import PromptTask, ollama_chat_model_factory

chat = PromptTask(
    name='chat',
    prompt='echo {{ " ".join(input._args) if input._args | length > 0 else "tell me some fun fact" }}',  # noqa
    system_prompt='You are a code tutor. You eager to explain code in a very detail manner',  # noqa
    chat_model_factory=ollama_chat_model_factory(
        model='mistral',
        temperature=0.8,
        num_gpu=0,
    ),
    history_file='.ctx.json'
)
runner.register(chat)
zrb chat "Please explain the following Python script: $(cat fibo.py)"
See the result:
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:11:54.418 โ  32106 โ†’ 1/3 ๐Ÿป            zrb chat โ€ข Context file: .ctx.json
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:11:54.418 โ  32106 โ†’ 1/3 ๐Ÿป            zrb chat โ€ข Sending request...
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:24:32.398 โ  32106 โ†’ 1/3 ๐Ÿป            zrb chat โ€ข Waiting for response...
    Sure thing! This code defines a Python function named `fibo` that calculates the Fibonacci sequence up to the nth number. Here's a step-by-step breakdown of how it works:

    1. The function definition begins with `def fibo(n):`, which means we are defining a function named `fibo` that takes one argument, `n`.
    2. The first line inside the function is an if statement: `if n <= 1:` This statement checks if the value of `n` is less than or equal to 1. If it is, then the condition is true and we execute the code inside the indented block.
    3. Inside the if block, we return the value `1`. This is the base case for our Fibonacci sequence. The first number in the sequence (indexed at 0) is always 0, and the second number (indexed at 1) is always 1. Since our function accepts an argument of `n` instead of `n-1`, we set the base case to be when `n` is less than or equal to 1, which corresponds to the first two numbers in the sequence.
    4. If the condition in the if statement is false (i.e., if `n > 1`), then we execute the code outside of the if block. The first line here is a recursive call to `fibo(n-1)`. This means that we are calling the `fibo` function with an argument one less than our original `n`, which corresponds to the previous number in the sequence.
    5. The second recursive call inside the function is `fibo(n-2)`, which calculates the next number before that in the sequence.
    6. Finally, we return the sum of the results from the two most recent calls to `fibo`: `return fibo(n-1) + fibo(n-2)`. This is how we calculate the nth number in the Fibonacci sequence by adding together the previous two numbers.
    7. The last lines of the code are an if statement that checks if the script is being run directly (`if __name__ == '__main__'`), and if so, it prints out the result of calling `fibo(8)`. This allows us to test the function with a specific input value.
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:27:42.230 โ  32106 โ†’ 1/3 ๐Ÿป            zrb chat โ€ข Response completed
Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:27:42.245 โ  32106 โ†’ 1/3 ๐Ÿป            zrb chat โ€ข Completed in 947.8267965316772 seconds
To run again: zrb chat "Explain this code: def fibo(n):
    if n <= 1:
        return 1
    return fibo(n-1) + fibo(n-2)


if __name__ == '__main__':
    print(fibo(8))"
zrb chat "Can you make it better?"
See the result:
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:29:37.978 โ  39864 โ†’ 1/3 ๐Ÿ            zrb chat โ€ข Context file: .ctx.json
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:29:37.978 โ  39864 โ†’ 1/3 ๐Ÿ            zrb chat โ€ข Sending request...
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:32:21.021 โ  39864 โ†’ 1/3 ๐Ÿ            zrb chat โ€ข Waiting for response...
    Certainly! The current implementation of the `fibo` function using recursion is a common and effective way to calculate Fibonacci numbers, but it can be memory intensive for large inputs due to the repeated calculation of intermediate results. A more space-efficient alternative is to use an iterative approach instead.

    Here's an example of how you could modify the `fibo` function to use iteration:

    ```python
    def fibo(n):
        if n <= 0:
            return "Input should be positive integer"
        elif n == 1:
            return 1
        else:
            a, b = 1, 1
            for _ in range(n - 1):
                a, b = b, a + b
            return b

    if __name__ == '__main__':
        print(fibo(8))
    ```

    In this version of the function:

    1. We still start by checking for edge cases, including `n <= 0`, which returns an error message and is not part of the Fibonacci sequence. We also check if `n == 1`, which is our base case and sets the initial value of our sequence to 1.                                                                            2. For larger values of `n`, we use a pair of variables, `a` and `b`, initialized to 1 in this example, to represent the previous two numbers in the Fibonacci sequence. We then enter a for loop that runs `n-1` times.                                                                                                  3. In each iteration of the loop, we update the values of `a` and `b` by swapping their values (`a, b = b, a + b`) and moving the new value of `b` one step forward in the sequence. This allows us to calculate each number in the sequence without having to store all previous results in memory.
    4. Finally, we return the value of `b`, which is now the nth number in the Fibonacci sequence.

    Using an iterative approach can be more space-efficient than recursion for large inputs, as it avoids the need to maintain a growing call stack. However, the choice between recursion and iteration ultimately depends on the specific use case and performance requirements of your application.
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:36:05.722 โ  39864 โ†’ 1/3 ๐Ÿ            zrb chat โ€ข Response completed
Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-12-28 18:36:05.723 โ  39864 โ†’ 1/3 ๐Ÿ            zrb chat โ€ข Completed in 387.7480981349945 seconds    
To run again: zrb chat "Can you make it better?"

Configuration

You can configure Zrb Ollama using a few environment variables:

  • ZRB_OLLAMA_BASE_URL: Default Ollama base URL. If not specified, Zrb Ollama will use http://localhost:11434.
  • ZRB_OLLAMA_DEFAULT_MODEL: Default Ollama model. If not specified, Zrb Ollama will use mistral.
  • ZRB_OLLAMA_VERBOSE_EVAL: Whether zrb-ollama-py shows the evaluated source code or not. If not specified, Zrb Ollama will set this to 0

For maintainers

Publish to pypi

To publish zrb-ollama, you need to have a Pypi account:

You can also create a TestPypi account:

Once you have your API token, you need to create a ~/.pypirc file:

[distutils]
index-servers =
   pypi
   testpypi

[pypi]
  repository = https://upload.pypi.org/legacy/
  username = __token__
  password = pypi-xxx-xxx
[testpypi]
  repository = https://test.pypi.org/legacy/
  username = __token__
  password = pypi-xxx-xxx

To publish zrb-ollama, you can do the following command:

zrb plugin publish

Updating version

You can update zrb-ollama version by modifying the following section in pyproject.toml:

[project]
version = "0.0.2"

Adding dependencies

To add zrb-ollama dependencies, you can edit the following section in pyproject.toml:

[project]
dependencies = [
    "Jinja2==3.1.2",
    "jsons==1.6.3"
]

Adding script

To make zrb-package-name executable, you can edit the following section in pyproject.toml:

[project-scripts]
zrb-ollama = "zrb-ollama.__main__:hello"

This will look for hello callable inside of your __main__.py file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zrb_ollama-0.0.12.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

zrb_ollama-0.0.12-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file zrb_ollama-0.0.12.tar.gz.

File metadata

  • Download URL: zrb_ollama-0.0.12.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for zrb_ollama-0.0.12.tar.gz
Algorithm Hash digest
SHA256 c44976e1e1fdf8849a4cca34d71755298aca92df85350091b1155c9d8601171d
MD5 913b026957c826d77dd1eac6dda258cc
BLAKE2b-256 90a4828e2107105ca931cf4b5443c1533de6b43411692410be7f4ed130c23507

See more details on using hashes here.

File details

Details for the file zrb_ollama-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: zrb_ollama-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for zrb_ollama-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 0051671def414547c7afad28c4e63897b9e59da20a2b4c3c0f02f6d989e4d2bc
MD5 7ea1d638954f3f4e14569d43f5820c5e
BLAKE2b-256 ab56a9c56acce7fcc799e0b264ce06042f72a3db2692bc93b7c1559ba5b9b351

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page