How to Integrate Xunfei Starfire Cognitive Model into PHP Projects – Step-by-Step Guide
This guide walks you through the background of Xunfei's Starfire large language model, its 2.0 features, account setup, obtaining API credentials, cloning the example repository, installing dependencies, configuring keys, and troubleshooting common errors for PHP integration.
Starfire Cognitive Model
Starfire Cognitive Model (Starfire Cognitive Mode1) is an AI‑driven cognitive model that simulates human thinking and reasoning by combining natural language processing, machine learning, and knowledge‑graph technologies.
The model is trained on massive corpora to understand and answer questions, and it can be applied to intelligent customer service, Q&A systems, virtual assistants, and other scenarios.
Version 2.0 Features
Stronger natural language processing powered by larger training data and deeper neural networks, yielding more accurate and fluent responses.
Richer knowledge base that can provide professional, in‑depth explanations and suggestions.
More personalized service by leveraging user profiles and interaction history.
Higher security and reliability with multiple safeguards to protect data privacy and ensure stable operation.
Preparation
Access the Starfire portal: https://xinghuo.xfyun.cn/
API free trial is available.
Note: you must register an account first; existing accounts can skip this step.
Steps to obtain credentials:
Create a new application in the console and claim free tokens.
Retrieve APPID, APISecret and APIKey from the Open Platform console: https://console.xfyun.cn/services/cbm
Reference the Web API documentation: https://www.xfyun.cn/doc/spark/Web.html
Test the service via the online demo: https://xinghuo.xfyun.cn/desk
Example Code
Repository: https://gitee.com/Tinywan_admin/spark.chatgpt.tinywan.com
Get the Code
git clone [email protected]:Tinywan_admin/spark.chatgpt.tinywan.com.gitInstallation
Third‑party WebSocket library used: https://github.com/Textalk/websocket-php
cd spark.chatgpt.tinywan.com
composer require textalk/websocketConfigure Credentials
Copy the APPID , APIKey and APISecret obtained from the console into the corresponding fields of Spark.php .
$Appid = "007e50a0";
$Apikey = "UyZmNjNxxxxxxxxxxxxGY1Mzk3";
$ApiSecret = "5459f0f1xxxxxxxxxxxxxxxd9ef7af4e";Run a Test
Example: implement a bubble‑sort algorithm in PHP to verify the model call.
Common Issues
401 Unauthorized
Sec-WebSocket-Accept not found. Header:
HTTP/1.1 401 Unauthorized
Date: Sun, 22 Oct 2023 00:04:37 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Content-Length: 76
Server: kong/1.3.0Solution: verify that ApiKey and SecretKey are not swapped.
AppIdNoAuthError
{
"header": {
"code": 11200,
"message": "AppIdNoAuthError:(07:59:51.663) domain.general",
"sid": "cht000a4b97@dx18b54ae4f68b8f3540",
"status": 2
}
}Solution: ensure your account has permission to use the 2.0 model.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
