mirakmalsulton/llmsql 问题修复 & 功能扩展

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

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

mirakmalsulton/llmsql

Composer 安装命令:

composer require mirakmalsulton/llmsql

包简介

Interface for interacting with SQL databases using LLM.

README 文档

README

Below is an example of how to implement a natural language SQL interface within a Laravel route and view.

1. Route and Controller Logic

Add this to your routes/web.php. It automatically fetches your database schema, processes the question via the engine, and executes the generated SQL.

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
use Mirakmalsulton\LlmSql\LlmSqlEngine;
use Mirakmalsulton\LlmSql\Dto\Tables;

Route::match(['get', 'post'], '/sql', function (Request $request, LlmSqlEngine $engine) {
    $question = $request->input('question');
    $result = null;
    $rows = collect();
    $headers = [];

    if ($request->isMethod('post') && $question) {
        $allTables = Schema::getTableListing();
        $tables = new Tables();

        foreach ($allTables as $table) {
            $ddl = (array)DB::select("SHOW CREATE TABLE `{$table}`")[0];
            $columns = Schema::getColumnListing($table);
            $tables->addTable($table, $columns, $ddl['Create Table']);
        }

        try {
            $result = $engine->setTables($tables)->find($question);
            $dbData = DB::select($result['sql']);
            $rows = collect($dbData)->map(fn($item) => (array)$item);
            $headers = $rows->first() ? array_keys($rows->first()) : [];
        } catch (\Exception $e) {
            $headers = ['Error'];
            $rows = collect([['error' => $e->getMessage()]]);
        }
    }

    return view('welcome', [
        'result'   => $result,
        'rows'     => $rows,
        'headers'  => $headers,
        'question' => $question
    ]);
})->name('sql');

2. View (Blade)

Use the built-in widgets to render the search interface and the results table in your welcome.blade.php.

{{-- Render the SQL search widget --}}
{!! \Mirakmalsulton\LlmSql\Widgets\SimpleSqlWidget::render(route('sql'), $result, $question) !!}

{{-- Render results table if query was successful --}}
@if($result && isset($rows))
    <div style="margin-top: 30px;">
        <h4 style="font-family: sans-serif;">Results:</h4>
        {!! \Mirakmalsulton\LlmSql\Widgets\SimpleSqlWidget::renderTable($headers, $rows->toArray()) !!}
    </div>
@endif

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固