adachsoft/embedding-openai
最新稳定版本:v0.1.0
Composer 安装命令:
composer require adachsoft/embedding-openai
包简介
OpenAI Embeddings provider implementation for adachsoft/embedding-contracts.
README 文档
README
Provider-specific implementation of adachsoft/embedding-contracts for the OpenAI Embeddings API.
This library provides a production-ready implementation of EmbedderInterface that talks to the official OpenAI HTTP API using Guzzle and exposes a simple, DTO-based contract for generating text embeddings.
Installation
composer require adachsoft/embedding-openai
This will also install adachsoft/embedding-contracts and guzzlehttp/guzzle as dependencies.
Usage
<?php declare(strict_types=1);
use AdachSoft\EmbeddingContracts\Dto\EmbeddingRequestDto;
use AdachSoft\EmbeddingContracts\Enum\EmbeddingEncodingFormatEnum;
use AdachSoft\EmbeddingContracts\Enum\EmbeddingInputTypeEnum;
use AdachSoft\EmbeddingOpenai\OpenAiEmbedder;
use GuzzleHttp\Client;
$client = new Client();
$apiKey = $_ENV['OPENAI_API_KEY'] ?? getenv('OPENAI_API_KEY');
$embedder = new OpenAiEmbedder($client, (string) $apiKey);
$request = new EmbeddingRequestDto(
input: 'hello world',
model: 'text-embedding-3-small',
inputType: EmbeddingInputTypeEnum::Query,
encodingFormat: EmbeddingEncodingFormatEnum::Float,
);
$response = $embedder->embed($request);
// $response->vector now contains the embedding for "hello world".
Testing
The project ships with a production integration test that talks to the real OpenAI API.
To run it, you must provide a valid API key via OPENAI_API_KEY in your environment (or .env file) and then execute:
vendor/bin/phpunit --group production
By default, this production test group is excluded from the regular test suite.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-23