akramzerarka/llama-cpp-php

该软件包允许在PHP中使用LLama C++库,从而能够在本地机器上设置和执行LLM模型。

v0.3 2024-02-21 07:01 UTC

This package is auto-updated.

Last update: 2024-09-21 08:05:11 UTC


README

Latest Version on Packagist Tests Total Downloads

该软件包允许在PHP中使用LLama C++库,从而能够在本地机器上设置和执行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)。请参阅许可证文件以获取更多信息。