amohamed/jsconnector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

amohamed/jsconnector

Composer 安装命令:

composer create-project amohamed/jsconnector

包简介

JSConnector Laravel Package provides an easy way to integrate the JSConnector JavaScript library into your Laravel application. This package offers a simple facade to interact with the JSConnector library, enabling developers to leverage the power of OpenAI's language models in their Laravel project

README 文档

README

The Laravel JS Connector package provides an easy way to integrate the JSConnector JavaScript library into your Laravel application. This package offers a simple facade to interact with the JSConnector library, enabling developers to leverage the power of OpenAI's language models in their Laravel projects without the hassle of directly managing communication between PHP and JavaScript.

Installation

You can install the package via composer:

composer require amohamed/jsconnector

Configuration

Publish the config file with:

php artisan vendor:publish --provider="Amohamed\JSConnector\JSConnectorServiceProvider" --tag="config"

This is the contents of the config file:

return [
    'api_url' => env('JS_CONNECTOR_API_URL', 'http://localhost:3000/api'),
    'retry_times' => env('JS_CONNECTOR_RETRY_TIMES', 3),
    'retry_interval' => env('JS_CONNECTOR_RETRY_INTERVAL', 100),
];

You can customize the values in the .env file like so:

JS_CONNECTOR_API_URL=http://localhost:3000/api
JS_CONNECTOR_RETRY_TIMES=3
JS_CONNECTOR_RETRY_INTERVAL=100

Starting and Stopping the Node.js Server

Before you can start making requests with JSConnector, you need to ensure that the Node.js server is running. You can start the server with the provided artisan command:

php artisan jsconnector:serve

To stop the running server, you can use:

php artisan jsconnector:stop

Usage

Here is a basic example of how to use the JS Connector:

$response = JSConnector::post('test-endpoint', ['baz' => 'qux']);

Usage with LangChain JS

To use JSConnector with LangChain JS in your Laravel application, you need to install LangChain JS first. You can do this by running:

npm install -S langchain

Then, on your Node.js server, you can create a JavaScript file where you import and initialize LangChain:

require('dotenv').config();

const { OpenAI } = require('langchain/llms/openai');
const { BufferMemory } = require('langchain/memory');
const { ConversationChain } = require('langchain/chains');

const model = new OpenAI({ key: process.env.OPENAI_API_KEY });
const memory = new BufferMemory();
const chain = new ConversationChain({ llm: model, memory: memory });
const cors = require('cors');

const express = require('express');
const app = express();
app.use(cors());

app.use(express.json());

app.post('/chat', async (req, res) => {
    console.log(`Request body: ${JSON.stringify(req.body)}`);
    const result = await chain.call({ input: req.body.input });
    console.log(`API response: ${JSON.stringify(result)}`);
    res.send(result);
});

app.listen(3000, () => {
    console.log('Langchain server running on port 3000');
});

In your Laravel application, you can use the JSConnector to send data to the LangChain JS service:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Amohamed\JSConnector\Facades\JSConnector;

class LangChainController extends Controller
{
    public function chat(Request $request)
    {
        $input = $request->input('message');

        // We use the post method on the JSConnector facade
        $response = JSConnector::post('chat', ['input' => $input]);

        // Then we return the response from the langchainjs service
        return response()->json(['response' => $response]);
    }
}

Route::post('/chat', 'App\Http\Controllers\LangChainController@chat');

This will send the response from the LangChain JS service back to the client.

Testing

Run the tests with:

vendor/bin/phpunit

License

The Laravel JS Connector is open-sourced software licensed under the MIT license.

Authors

Abdallah Mohamed (abdal_cascad@hotmail.com)

amohamed/jsconnector 适用场景与选型建议

amohamed/jsconnector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 amohamed/jsconnector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 amohamed/jsconnector 我们能提供哪些服务?
定制开发 / 二次开发

基于 amohamed/jsconnector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-17