nandung/copilot-proxy
Composer 安装命令:
composer require nandung/copilot-proxy
包简介
PHP library for GitHub Copilot API proxy - OpenAI and Anthropic compatible
README 文档
README
PHP library untuk mengakses GitHub Copilot API dengan interface OpenAI-compatible.
Requirements
- PHP 8.1+
- Active GitHub Copilot subscription
Installation
composer require nandung/copilot-proxy
Quick Start
1. Authentication (First Time Only)
<?php use Nandung\CopilotProxy\CopilotProxy; // Get device code $auth = CopilotProxy::auth(); $deviceCode = $auth->getDeviceCode(); echo "Go to: {$deviceCode->verificationUri}\n"; echo "Enter code: {$deviceCode->userCode}\n"; // Wait for user to authorize (polls automatically) $githubToken = $auth->pollAccessToken($deviceCode, function($attempt, $max) { echo "Waiting for authorization... ({$attempt}/{$max})\n"; }); // Save token for later use file_put_contents('github_token.txt', $githubToken); echo "Token saved!\n";
2. Using the API
<?php use Nandung\CopilotProxy\CopilotProxy; $proxy = new CopilotProxy(file_get_contents('github_token.txt')); // Simple question $answer = $proxy->ask('What is the capital of France?'); echo $answer; // Paris // Get user info $user = $proxy->getUser(); echo "Logged in as: {$user['login']}\n";
API Reference
Chat Completions
// Non-streaming $response = $proxy->chat([ 'model' => 'gpt-4.1', 'messages' => [ ['role' => 'system', 'content' => 'You are a helpful assistant.'], ['role' => 'user', 'content' => 'Hello!'] ], 'max_tokens' => 1000, 'temperature' => 0.7, ]); echo $response->getContent(); echo "Tokens used: {$response->usage['total_tokens']}\n"; // Streaming foreach ($proxy->chatStream([ 'model' => 'gpt-4.1', 'messages' => [['role' => 'user', 'content' => 'Tell me a story']] ]) as $chunk) { echo $chunk->getDeltaContent(); flush(); }
Available Models
$models = $proxy->models(); foreach ($models as $model) { echo "- {$model->id} ({$model->vendor})\n"; echo " Max tokens: {$model->getMaxOutputTokens()}\n"; }
Embeddings
$embedding = $proxy->embeddings('Hello world', 'text-embedding-3-small'); $vector = $embedding->getFirstEmbedding(); echo "Vector dimensions: " . count($vector) . "\n";
Tools / Function Calling
$response = $proxy->chat([ 'model' => 'gpt-4.1', 'messages' => [ ['role' => 'user', 'content' => 'What is the weather in Tokyo?'] ], 'tools' => [ [ 'type' => 'function', 'function' => [ 'name' => 'get_weather', 'description' => 'Get weather for a location', 'parameters' => [ 'type' => 'object', 'properties' => [ 'location' => ['type' => 'string'] ], 'required' => ['location'] ] ] ] ] ]); $toolCalls = $response->getMessage()->toolCalls ?? []; foreach ($toolCalls as $call) { echo "Function: {$call['function']['name']}\n"; echo "Arguments: {$call['function']['arguments']}\n"; }
Account Types
// Individual (default) $proxy = new CopilotProxy($token, 'individual'); // Business $proxy = new CopilotProxy($token, 'business'); // Enterprise $proxy = new CopilotProxy($token, 'enterprise');
Error Handling
use Nandung\CopilotProxy\Exceptions\CopilotException; try { $response = $proxy->chat([...]); } catch (CopilotException $e) { echo "Error: {$e->getMessage()}\n"; echo "Status: {$e->getStatusCode()}\n"; if ($errorData = $e->getErrorData()) { print_r($errorData); } }
Laravel Integration
// In AppServiceProvider use Nandung\CopilotProxy\CopilotProxy; public function register() { $this->app->singleton(CopilotProxy::class, function () { return new CopilotProxy(config('services.copilot.token')); }); } // Usage in controller public function index(CopilotProxy $proxy) { return $proxy->ask('Hello!'); }
License
MIT
nandung/copilot-proxy 适用场景与选型建议
nandung/copilot-proxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nandung/copilot-proxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nandung/copilot-proxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-17