承接 evoware/ollama-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evoware/ollama-php

最新稳定版本:v0.3.0

Composer 安装命令:

composer require evoware/ollama-php

包简介

A PHP library for interacting with local Ollama server.

README 文档

README

A comprehensive PHP library designed for seamless interaction with the Ollama server, facilitating a range of operations from generating text completions to managing models and producing embeddings.

But what's Ollama? Ollama is a tool for running open-source Large Language Models locally. You can find more information about Ollama directly at the project repository or documentation page.

Installation

To integrate the Ollama PHP Adapter into your project, use Composer for a smooth installation process:

composer require evoware/ollama-php

Usage:

The Ollama PHP Adapter simplifies the complexity of interacting with the Ollama server, providing intuitive methods for various functionalities.

Generating Text Completions

Generate text completions by providing a prompt to the model. Access the completion text using the getResponse() method:

use GuzzleHttp\Client as HttpClient;
use Evoware\OllamaPHP\OllamaClient;

$ollamaClient = new OllamaClient(new HttpClient());

$response = $ollamaClient->generateCompletion('The capital of France is ', ['model' => 'mistral:7b']);
$completionText = $response->getResponse(); // Returns the generated completion text.

Interacting with models:

Manage your local models by listing, pulling, and interacting through the provided methods:

// List all local models
$models = $ollamaClient->model()->list();

// Pull a local model
$result = $ollamaClient->model()->pull('mistral:7b');

// Alternatively, access via the getModelRepository method
$result = $ollamaClient->getModelRepository()->pull('mistral:7b');

// Load a Modelfile
$ollamaClient->fromModelFile('/path/to/modelfile');

To learn more about model file format, please visit Ollama Model File documentation here.

Generating embeddings:

Produce embeddings for a given text, returning an array of embedding data through the EmbeddingsResponse object:

$embeddings = $ollamaClient->generateEmbeddings('This is my text to be embedded.', 'nomic-embed-text');

Response Types

The adapter delineates responses into specific object types for clarity and ease of use:

  • CompletionResponse: Handles the data from text completion requests.
  • ChatCompletionResponse: Manages chat completion data.
  • EmbeddingsResponse: Encapsulates embedding data.
  • ModelOperationResponse: Represents the outcome of model operations (create, delete, pull, etc.).

Responses provide access to the underlying Guzzle Response via the getHttpResponse() method for further customization and handling.

Roadmap

  • Handling streaming responses.
  • Introduction of ChatSession class for storing chat context in a styructured manner.
  • Laravel facade support

Caution

⚠️ Development Stage: This project is in its early development stages and is not recommended for production environments. It is provided as-is, without any guarantees. Proceed with caution and use at your own risk. ⚠️

统计信息

  • 总下载量: 1.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 4
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固