kambo/llama-cpp-php

此软件包允许在PHP中使用LLama C++库,因此可以在本地机器上使用PHP设置和执行LLM模型。

v0.2.0-alpha 2023-04-24 17:17 UTC

This package is auto-updated.

Last update: 2024-08-24 20:06:09 UTC


README

Latest Version on Packagist Tests Total Downloads

此软件包允许在PHP中使用LLama C++库,因此可以在本地机器上使用PHP设置和执行LLM模型。

这是一个高度实验性的项目,不适用于生产环境!

自行承担风险!

仅支持Linux!

asciicast

安装

您可以通过composer安装此包

composer require kambo/llama-cpp-php kambo/llama-cpp-php-linux-lib

注意:kambo/llama-cpp-php-linux-lib包包含Linux的二进制库。

使用方法

获取模型,您可以使用如下命令

wget https://hugging-face.cn/LLukas22/gpt4all-lora-quantized-ggjt/resolve/main/ggjt-model.bin
$template = "You are a programmer, write PHP class that will add two numbers and print the result. Stop at class end.";
$context = Context::createWithParameter(new ModelParameters(__DIR__ .'/models/ggjt-model.bin'));
$llama = new LLamaCPP($context);
echo "Prompt: \033[0;32m".$template."\033[0m".PHP_EOL;

foreach ($llama->generate($template, new GenerationParameters(predictLength: 200)) as $token) {
    echo $token;
}

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。