承接 datalumo/php-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

datalumo/php-sdk

最新稳定版本:0.3.0

Composer 安装命令:

composer require datalumo/php-sdk

包简介

Official PHP SDK for the Datalumo API

README 文档

README

Official PHP SDK for the datalumo API.

Requirements

  • PHP 8.2+

Installation

composer require datalumo/php-sdk

Quick start

use Datalumo\PhpSdk\Datalumo;

$datalumo = new Datalumo('your-api-token');

Collections

Collections are containers for your content. Use them to manage your data.

List collections

$response = $datalumo->collections()->list();

foreach ($response->data as $collection) {
    echo $collection->name;
}

// Filter by project or paginate
$response = $datalumo->collections()->list(project: 'docs', page: 2);

Create a collection

$collection = $datalumo->collections()->create('My Collection');
$collection = $datalumo->collections()->create('My Collection', project: 'docs');

Update a collection

$collection = $datalumo->collections()->update('collection-id', 'New Name');

Delete a collection

$datalumo->collections()->delete('collection-id');

Entries

Entries are the individual pieces of content inside a collection.

$entries = $datalumo->entries('collection-id');

List entries

$response = $entries->list();
$response = $entries->list(page: 2);

Create an entry

$entry = $entries->create([
    'raw_text' => 'The content to index',
    'title' => 'My Entry',
    'meta' => ['author' => 'John'],
    'source_url' => 'https://example.com/page',
    'source_type' => 'articles',
    'source_id' => '42',
]);

Only raw_text is required. All other fields are optional.

Upsert an entry

Create or update by source_type and source_id:

$entry = $entries->upsert([
    'raw_text' => 'Updated content',
    'source_type' => 'articles',
    'source_id' => '42',
]);

Batch upsert

Create or update up to 50 entries at once:

$result = $entries->batchUpsert([
    ['raw_text' => 'First entry', 'source_type' => 'articles', 'source_id' => '1'],
    ['raw_text' => 'Second entry', 'source_type' => 'articles', 'source_id' => '2'],
]);

echo $result['created']; // 2
echo $result['updated']; // 0

Update an entry

$entry = $entries->update('entry-id', ['title' => 'Updated Title']);

Delete an entry

$entries->delete('entry-id');
$entries->deleteBySource('articles', '42');

Integrations

Integrations are the consumption layer — search, summarise, and chat all go through an integration. Each integration connects to one or more collections.

List integrations

$response = $datalumo->integrations()->list();
$response = $datalumo->integrations()->list(type: 'chatbot', project: 'support');

Get an integration

$integration = $datalumo->integrations()->get('integration-id');

Create an integration

$integration = $datalumo->integrations()->create([
    'type' => 'chatbot',
    'name' => 'Support Bot',
    'collection_ids' => ['col-1', 'col-2'],
    'accent_color' => '#3b82f6',
    'allowed_domains' => ['example.com'],
    'welcome_message' => 'How can I help?',
    'persona' => 'friendly',
]);

Update / delete

$datalumo->integrations()->update('integration-id', ['name' => 'Updated Bot']);
$datalumo->integrations()->delete('integration-id');

Record an event

$datalumo->integrations()->recordEvent('integration-id', [
    'event_type' => 'thumbs_up', // 'click', 'thumbs_up', or 'thumbs_down'
    'meta' => ['url' => 'https://example.com/page'],
]);

Search

$results = $datalumo->integrations()->search('integration-id', [
    'query' => 'how do refunds work',
    'threshold' => 0.3,
    'meta' => ['category' => 'billing'],
    'per_page' => 10,
    'page' => 1,
]);

foreach ($results->data as $entry) {
    echo $entry->title;
}

echo $results->summarisable; // true if good for summarisation

Summarise

$summary = $datalumo->integrations()->summarise('integration-id', [
    'query' => 'explain your refund policy',
    'format' => 'html', // 'markdown' (default) or 'html'
    'locale' => 'en',
]);

echo $summary->summary;
echo $summary->references;
echo $summary->hasRelevantResults;

Chat

$response = $datalumo->integrations()->chat('integration-id', [
    'message' => 'What is your refund policy?',
]);

echo $response->message;
echo $response->conversationId;

// Continue the conversation
$followUp = $datalumo->integrations()->chat('integration-id', [
    'message' => 'How long do I have?',
    'conversation_id' => $response->conversationId,
]);

Streaming

The summarise and chat endpoints support streaming via SSE:

Stream chat

$stream = $datalumo->integrations()->streamChat('integration-id', [
    'message' => 'What is your refund policy?',
]);

foreach ($stream->text() as $chunk) {
    echo $chunk;
    flush();
}

Stream summarise

$stream = $datalumo->integrations()->streamSummarise('integration-id', [
    'query' => 'explain the refund policy',
]);

foreach ($stream->text() as $chunk) {
    echo $chunk;
    flush();
}

Full text

$stream = $datalumo->integrations()->streamChat('integration-id', [
    'message' => 'hello',
]);

$fullResponse = $stream->fullText();

Raw stream events

foreach ($stream as $event) {
    if ($event->isTextDelta()) {
        echo $event->data;
    } elseif ($event->isCitation()) {
        // $event->citation() returns ['title' => '...', 'url' => '...']
    } elseif ($event->isStreamEnd()) {
        break;
    }
}

Error handling

use Datalumo\PhpSdk\Exceptions\AuthenticationException;
use Datalumo\PhpSdk\Exceptions\ValidationException;
use Datalumo\PhpSdk\Exceptions\NotFoundException;
use Datalumo\PhpSdk\Exceptions\QuotaExceededException;
use Datalumo\PhpSdk\Exceptions\DatalumoException;

try {
    $datalumo->collections()->create('');
} catch (ValidationException $e) {
    $e->getMessage(); // "The name field is required."
    $e->errors();     // ['name' => ['The name field is required.']]
} catch (AuthenticationException $e) {
    // 401 or 403
} catch (QuotaExceededException $e) {
    // 402
} catch (NotFoundException $e) {
    // 404
} catch (DatalumoException $e) {
    // Any other API error
}

Data objects

All API responses are returned as typed data objects:

Class Properties
Collection id, organisationId, name, project, createdAt, updatedAt
Entry id, collectionId, title, rawText, meta, sourceUrl, sourceType, sourceId, createdAt, updatedAt
Integration id, name, project, type, accentColor, allowedDomains, isActive, settings, collectionIds, createdAt, updatedAt
PaginatedResponse data, currentPage, lastPage, perPage, total, hasMorePages()
SearchResult Same as PaginatedResponse plus summarisable
SummaryResponse summary, references, data, hasRelevantResults
ChatResponse conversationId, message
StreamResponse Iterable of StreamEvent, plus text(), fullText(), conversationId()
StreamEvent type, data, raw, plus isTextDelta(), isCitation(), isStreamEnd(), isError()

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固