Skip to content

10up/wordpress-ai-client-provider-ollama

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

WordPress AI Client Provider for Ollama

Ollama provider for the PHP AI Client SDK. Works as both a Composer package with the php-ai-client package and as a WordPress plugin with the wp-ai-client plugin.

Ollama lets you run large language models locally or remotely. Ollama exposes an OpenAI-compatible API, and this provider uses that API to communicate with any model you have pulled into Ollama (Llama, Mistral, Gemma, Phi, and many more) or any available Ollama Cloud model.

Requirements

Installation

As a WordPress Plugin

  1. Install and activate the wp-ai-client plugin.
  2. Place this plugin in your wp-content/plugins/ directory.
  3. Activate "WordPress AI Client Provider for Ollama" from the Plugins screen.

As a Composer Package

composer require wordpress/ai-client-provider-ollama

Configuration

Ollama Host URL

By default, the provider connects to http://localhost:11434. You can change this in two ways:

  1. Environment variable (takes precedence): Set the OLLAMA_HOST environment variable.
  2. WordPress admin: Go to Settings > Ollama Settings and enter your Ollama host URL.

API Key

For local Ollama instances, no API key is needed. The plugin automatically registers an empty API key as a fallback.

For remote Ollama instances that require authentication (e.g., Ollama Cloud), enter the API key in the wp-ai-client Settings > AI Credentials screen. If using Ollama Cloud, you also need to set your Ollama host URL in the Settings > Ollama Settings screen to https://ollama.com.

Usage

With WordPress (wp-ai-client)

use WordPress\AI_Client\Prompt_Builder;

$result = Prompt_Builder::create()
    ->using_provider( 'ollama' )
    ->set_system_instruction( 'You are a helpful assistant.' )
    ->add_text_message( 'Hello, how are you?' )
    ->generate_text();

Standalone PHP (php-ai-client)

use WordPress\AiClient\AiClient;
use WordPress\AiClient\Providers\Http\DTO\ApiKeyRequestAuthentication;
use WordPress\AiClientProviderOllama\Provider\OllamaProvider;

require_once 'vendor/autoload.php';

$registry = AiClient::defaultRegistry();
$registry->registerProvider(OllamaProvider::class);
$registry->setProviderRequestAuthentication('ollama', new ApiKeyRequestAuthentication(''));

$result = AiClient::prompt('Hello!')
    ->usingProvider('ollama')
    ->generateText();

Like what you see?

Work with the 10up WordPress Practice at Fueled

About

Ollama provider for the PHP and WP AI Client packages

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published