Integrating Moonshot AI Model into Webman 5.0 with PHP

This guide explains how to add Moonshot's large language model to the Webman 5.0 framework, covering feature highlights, driver and processor implementation in PHP, configuration of model mappings, role settings, and practical code snippets for seamless AI integration.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
Integrating Moonshot AI Model into Webman 5.0 with PHP

Moonshot AI Overview

Moonshot AI focuses on general artificial intelligence, aiming to convert energy into intelligence and provide inclusive AI services. The core team contributed to key algorithms such as Transformer‑XL and RoPE, giving them deep expertise in large‑model development.

WebmanAI 5.0 Release Highlights

Full compatibility with Midjourney, supporting high‑resolution generation, image expansion, and local detail redraw.

Completely refactored architecture for clearer logic and higher efficiency, with easier integration of additional models.

Role privacy protection that hides user roles during creation.

Per‑API‑key endpoint customization for flexible configuration.

Ongoing performance optimizations for smoother, more stable usage.

Model‑Driven Integration (Driver)

File location:

plugin/ai/app/handler/driver/Moonshot.php
<?php
/**
 * @desc Model driver
 */
namespace plugin\ai\app\handler\driver;

use Webman\Openai\Chat;
use Workerman\Http\Response;

class Moonshot extends Chat {
    /** @var string API endpoint */
    protected $api = 'https://api.moonshot.cn';

    /**
     * completions implementation
     * @param array $data
     * @param array $options
     */
    public function completions(array $data, array $options) {
        if (isset($options['complete'])) {
            $options['complete'] = function ($result, Response $response) use ($data, $options) {
                if (isset($result['error'])) {
                    return $options['complete']($result, $response);
                }
                $options['complete']($result['choices'][0]['message']['content'], $response);
            };
        }
        if (isset($options['stream'])) {
            $options['stream'] = function ($data) use ($options) {
                $data = array_merge(['content' => ''], $data);
                unset($data['model']);
                $data['content'] = $data['choices'][0]['delta']['content'] ?? '';
                $options['stream']($data);
            };
        }
        parent::completions($data, $options);
    }
}

Model Processor

File location:

plugin/ai/app/handler/Moonshot.php
<?php
/**
 * @desc Model processor
 */
declare(strict_types=1);

namespace plugin\ai\app\handler;

class Moonshot extends Base {
    protected static $name = 'Moonshot';
    protected static $type = 'moonshot';
    public static $models = [
        'moonshot-v1-8k',
        'moonshot-v1-32k',
        'moonshot-v1-128k',
    ];
    public static $defaultSettings = [
        'api' => [
            'name' => 'API',
            'type' => 'text',
            'value' => 'https://api.moonshot.cn',
            'desc' => 'API address',
        ],
        'regFreeCount' => [
            'name' => 'Registration Gift',
            'type' => 'number',
            'value' => 0,
        ],
        'dayFreeCount' => [
            'name' => 'Daily Gift',
            'type' => 'number',
            'value' => 0,
        ],
    ];
    protected $driverClass = driver\Moonshot::class;

    public function completions($data, $options) {
        $this->driver = new $this->driverClass($this->getSettings());
        $this->driver->completions($data, $options);
    }
}

AI Assistant Generic Configuration

Model mapping (JSON) used by the assistant:

{
    "gpt-3.5-turbo": "gpt-3.5-turbo",
    "gpt-3.5-turbo-0613": "gpt-3.5-turbo-0613",
    "gpt-3.5-turbo-16k": "gpt-3.5-turbo-16k",
    "gpt-4": "gpt-4",
    "gpt-4-32k": "gpt-4-32k",
    "qwen-plus": "通义千问",
    "ernie-bot-turbo": "文心一言",
    "spark": "讯飞星火",
    "gemini-pro": "gemini-pro",
    "moonshot-v1-8k": "月之暗面",
    "midjourney": "Midjourney作图",
    "dall.e": "DALL.E作图",
    "chatglm": "清华智普"
}

Additional configuration adds the Moonshot model and role:

Model entry 月之暗面 linked to the Moonshot API key.

Role configuration enables pre‑installation of the Moonshot role and selects the large model for generation.

Interface Preview

The following screenshots illustrate the WebmanAI 5.0 UI after integrating Moonshot:

Interface preview
Interface preview
Model configuration
Model configuration
Role configuration
Role configuration
Final UI
Final UI
PHPAI integrationWebmanAPI configurationModel driverModel processorMoonshot AI
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.