adrienbrault/hermes2pro

dev-main 2024-05-07 20:29 UTC

This package is auto-updated.

Last update: 2024-12-07 22:09:22 UTC


README

NousResearch/Hermes-2-Pro-Mistral-7B is an open source LLM with great function calling capabilities.

This PSR-18 plugin converts OpenAI API requests/responses that use function calling to and from the Hermes2Pro prompt format.

It lets you use Hermes2Pro function calling with the same OpenAI api client code that you currently use.

An http proxy docker image is available for non PHP projects.

PHP Library

Install ollama (docker) and pull the model:

$ ollama pull adrienbrault/nous-hermes2pro:Q4_K_M

Install this package:

$ composer require adrienbrault/hermes2pro:@dev

Then update your code to use the plugin:

use AdrienBrault\Hermes2Pro\Hermes2ProPlugin;
use Http\Client\Common\PluginClient;
use Http\Discovery\Psr18ClientDiscovery;

require_once __DIR__ . '/vendor/autoload.php';

$client = OpenAI::factory()
    ->withApiKey(getenv('OPENAI_API_KEY'))
    ->withBaseUri(sprintf(
        '%s/v1',
        getenv('OLLAMA_HOST') ?: 'http://localhost:11434'
    ))
    ->withHttpClient(
        new PluginClient(
            Psr18ClientDiscovery::find(),
            [
                new Hermes2ProPlugin()
            ]
        )
    )
    ->make()
;

Then use adrienbrault/nous-hermes2pro:Q4_K_M as the model in your chat requests. There are more tags/quantizations available.

The model and this plugin supports parallel function calling. Note that streaming is not currently supported.

Note that the plugin is only active if the request/response model starts with adrienbrault/nous-hermes2pro.

See demo/.

Docker Proxy

A docker http proxy is available to convert requests/responses to/from the Hermes2Pro format:

$ docker run -it --rm \
    -e OPENAI_BASE_URI=http://docker.for.mac.host.internal:11434 \
    -p 11440:80 \
    adrienbrault/hermes2pro-proxy

$ MODEL="adrienbrault/nous-hermes2pro:Q4_K_M" \
    OPENAI_BASE_URI="http://localhost:11440/v1" \
    php demo/openai.php