Code Monkey home page Code Monkey logo

ollama-functions's Introduction

alt text

ollama-functions

About

This boiler-plate project uses Ollama natively to invoke python function, and similar to LangChain Tools (but using native Ollama API only). it does this by leveraging the llm model called: calebfahlgren/natural-functions calebfahlgren/natural-functions

To make it flexible, i have opted for a runtime plugin system, which can be expanded to include your own functionality

Without any modifications you should use the llm model, since not all open llms are good enough to handle function invocation.

I have included two sample plugins: chrome_browser plugin and ebay_search plugin, which both use Chrome and OSX to go to a specific page based on the LLM input. You can modify it easily to accomidate Windows or Linux.

How to use:

Create venv and install requirements

python -m venv venv
source venv/bin/activate

pip install -r requirements.txt

Create .env file

# .env
OLLAMA_URL=http://<your_ollama_ip>:11434
# If no model is specified, you will get a select box
OLLAMA_MODEL=calebfahlgren/natural-functions:latest

Run it

source venv/bin/activate
python app.py

Extending the functionality

The plugin_loader is a simple class that loads the plugins from the plugins folder. In the sample code it looks into the plugin/ folder for any plugin.

a function plugin consists of the following file structure

|-Plugins
|-- <YOUR_PLUGIN_FOLDER>
|---- __init__.py
|---- plugin.py

The plugin.py inherits from the base class PluginInterface and implements the following methods:

from plugin_interface import PluginInterface

class nmap_scan_single_ip(PluginInterface):

    _schema =     {
      "name": "nmap_scan",
      "description": "Perform a nmap network scan on a single ip address.",
      "parameters": {
          "properties": {              
              "ipv4": "ipv4 or CIDR range",
              "description": "ipv4 or CIDR range address of scan target",
              "type": "string"
          }
      }
    }
    
    def get_schema(self):
        return self._schema
    
    def get_plugin_name(self):
        return self._schema['name'] 
    
    def get_plugin_description(self) -> str:
        return self._schema['description'] 
    
    def execute(self, parameters):
        print( f"Hello from {self.get_plugin_name()}")
        print(parameters)
        #  Do your magic here

In the schema you define how the LLM requires to call the Python method and its arguments you need to passthrough. The generic 'execute' method is invoked passing the arguments extracted by the LLM from the schem. During load, all schema's files are appended to the schema[] list and passed through as context for the LLM.

ollama-functions's People

Stargazers

Tony Tromp avatar Yan Zhabin avatar Dean Reedy avatar ヤーセル avatar Jeff avatar Stephen Arsenault avatar  avatar Bill Allen avatar Dezoito avatar Matthew MacLeod  avatar Ricardo Rivera avatar

Watchers

Tony Tromp avatar Dean Reedy avatar

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.