Code Monkey home page Code Monkey logo

ollama-laravel's Introduction

Ollama-Laravel Package

Ollama-Laravel is a Laravel package that provides a seamless integration with the Ollama API. It includes functionalities for model management, prompt generation, format setting, and more. This package is perfect for developers looking to leverage the power of the Ollama API in their Laravel applications.

If you use laravel 10.x, please use the following version V1.0.5

https://github.com/cloudstudio/ollama-laravel/releases/tag/v1.0.5

Installation

composer require cloudstudio/ollama-laravel

Configuration

php artisan vendor:publish --tag="ollama-laravel-config"

Published config file:

return [
    'model' => env('OLLAMA_MODEL', 'llama2'),
    'url' => env('OLLAMA_URL', 'http://127.0.0.1:11434'),
    'default_prompt' => env('OLLAMA_DEFAULT_PROMPT', 'Hello, how can I assist you today?'),
    'connection' => [
        'timeout' => env('OLLAMA_CONNECTION_TIMEOUT', 300),
    ],
];

Usage

Basic Usage

use Cloudstudio\Ollama\Facades\Ollama;

$response = Ollama::agent('You are a weather expert...')
    ->prompt('Why is the sky blue?')
    ->model('llama2')
    ->options(['temperature' => 0.8])
    ->stream(false)
    ->ask();

Vision Support

$response = Ollama::model('llava:13b')
    ->prompt('What is in this picture?')
    ->image(public_path('images/example.jpg')) 
    ->ask();

// "The image features a close-up of a person's hand, wearing bright pink fingernail polish and blue nail polish. In addition to the colorful nails, the hand has two tattoos – one is a cross and the other is an eye."

Chat Completion

$messages = [
    ['role' => 'user', 'content' => 'My name is Toni Soriano and I live in Spain'],
    ['role' => 'assistant', 'content' => 'Nice to meet you , Toni Soriano'],
    ['role' => 'user', 'content' => 'where I live ?'],
];

$response = Ollama::agent('You know me really well!')
    ->model('llama2')
    ->chat($messages);

// "You mentioned that you live in Spain."

Show Model Information

$response = Ollama::model('Llama2')->show();

Copy a Model

Ollama::model('Llama2')->copy('NewModel');

Delete a Model

Ollama::model('Llama2')->delete();

Generate Embeddings

$embeddings = Ollama::model('Llama2')->embeddings('Your prompt here');

Testing

pest

Changelog, Contributing, and Security

Credits

License

MIT License

ollama-laravel's People

Contributors

cloudstudio avatar jamonek avatar marianoarga avatar neoteknic avatar

Stargazers

Jens Kleikamp avatar Kojo Jeffery avatar  avatar Patrick Samson avatar Zander Lewis avatar trungta avatar Robin avatar yahya ahrika avatar Dan Alvidrez avatar r567tw avatar r567twjob avatar Faruk Nasir avatar Chris Vasey avatar zaimazhar avatar Fabrizio Balliano avatar Hilman Ibnu Assiddiq avatar Fabio Silva avatar Aurélien Schelcher avatar  avatar Vitaliy avatar  avatar Greg Jasiński avatar Ethan Thompson avatar guanguans avatar Jcoder avatar Philipp C. Gérard avatar Sam avatar Juan Diaz avatar Rev Mindbender avatar Daniel Proaño Chacón avatar  avatar Eric K avatar Xing1615 avatar Jonathan avatar Luis Carlos Aveiro avatar Roberto Butti avatar Silvio Ney avatar  avatar  avatar Fabio Pacifici avatar  avatar M. Vugteveen avatar Subhan Raj avatar Terran avatar Mykhailo Borovyk avatar Chimit avatar  avatar SteaveRayvon avatar Fred Bradley avatar Osaigbovo Emmanuel avatar Wuyq avatar Roland Edi avatar Elliot Goode avatar Jason Davis avatar Stephen Jude avatar  ShaoBo Wan(無尘) avatar Dziamid Harbatsevich avatar Justin Byrne avatar Benny Leonard Enrico Panggabean avatar Julian Lugod avatar Stupid Dev avatar Andreas Reinhold / surtic86 avatar Revaz Gh. avatar  avatar  avatar Yoga Bagas avatar Vytautas M. avatar Hans Nielsen avatar Eloquentize avatar Khongor Gerelchimeg avatar Suri avatar Jing Tai Piao avatar Raees avatar  avatar Hasan AlDoy avatar  avatar Maris avatar Brian Roach avatar Jayps avatar Gary Xu avatar Paradoxe Ng avatar Oleg Veselkov avatar Chumang avatar Paijiey avatar OrangBus avatar Usman Mughal avatar 噢哎哟喂 avatar Christoph Ostrzinski avatar Guile Lindroth avatar Kostas Charalampidis avatar Aditya Gupta avatar Jeffrey Morgan avatar Luiz Bartolomeu avatar Vineet Chauhan avatar Neeraj Kumar avatar Mikołaj Ilczyna avatar karyo avatar Tushar Bhatia avatar  avatar  avatar

Watchers

Jason Davis avatar Tarek Tarabichi avatar Fred Bradley avatar  avatar Guile Lindroth avatar Daniel Proaño Chacón avatar  avatar

ollama-laravel's Issues

Passing keep_alive

I have searched through the source code with no luck on figuring out how to pass keep_alive. Am I missing something here?

Stream chat

Hello, how could I consumen the chat or any stream? since this request responds with an array and not a resource (having "stream" true by default)

$response = Ollama::agent("You are an awesome assistant")
  ->model('llama2')
  ->stream(true)
  ->chat($this->conversation);
                
  dd($response)
               
  (returns array)

unauthorized

Highly likely issue on my end, however:
[ec2-user@app www]$ curl http://192.168.1.149:11434/api/generate -d '{
"model": "llama3",
"prompt": "Hey",
"stream":false
}'
{"model":"llama3","created_at":"2024-06-06T01:27:27.256766425Z","response":"Hey! How's it going?","done":true,"done_reason":"stop","context":[128006,882,128007,271,19182,128009,128006,78191,128007,271,19182,0,2650,596,433,2133,30,128009],"total_duration":2320969362,"load_duration":1230493,"prompt_eval_count":6,"prompt_eval_duration":798696000,"eval_count":8,"eval_duration":1479250000}[ec2-user@app www]$

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Cloudstudio\Ollama\Facades\Ollama;

class TestCommand extends Command
{
    protected $signature = 'test:command';
    protected $description = 'Test command';

    public function handle()
    {

        $response = Ollama::model('llama3')->show();
        print_r($response);
        }
}

shows:

[ec2-user@app www]$ php artisan test:command

Array
(
    [error] => unauthorized
)

Any thoughts?
Thanks!!

P.S. Config:

<?php

// Config for Cloudstudio/Ollama

return [
    'model' => env('OLLAMA_MODEL', 'llama3'),
    'url' => env('OLLAMA_URL', '192.168.1.149:11434'),
    'default_prompt' => env('OLLAMA_DEFAULT_PROMPT', 'Hello, how can I assist you today?'),
    'connection' => [
        'timeout' => env('OLLAMA_CONNECTION_TIMEOUT', 300),
    ],
];

Ability to use API key

The underlying llama.cpp has an --api-key option that I would like to utilize, but Ollama does not support. Their current recommendation appears to be setup your own proxy - which is fine - but I need to be able to pass the api key in the Guzzle request regardless if they support llama.cpp's option or my own proxy.

Is this something that makes sense to do a pull request for? I'm thinking a new .env variable and config key allowing the authorization header via Guzzle: Authorization: Bearer <apikey> added to https://github.com/cloudstudio/ollama-laravel/blob/main/src/Traits/MakesHttpRequests.php?

Browser timeout

First of all, ollama is working fine when i use the terminal.

When i use this package, i mostly get connection time out in de browser.

Example to use Embeddings?

thanks a lot for the package help me done so many things in my project, can you help to add more example to use Embeddings?

All responses are returning null

When I try to run just the default it returns null

        dd(\Cloudstudio\Ollama\Facades\Ollama::agent('You are a weather expert...')
            ->prompt('Why is the sky blue?')
            ->model('llama3')
            ->keepAlive('10m')
            ->options(['temperature' => 0.8])
            ->stream(false)
            ->ask());

It appears that OLLAMA_URL=http://ollama.test/ inside my .env gives enough information for the requests to proceed but the end result is not working. To fix it just remove the ending "/" so it will become - OLLAMA_URL=http://ollama.test

It could be fixed as a small amend on the code but there is still an easy fix with amending the url.

Hope that helps someone in the future.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.