fjffk简单的咖啡店科开发2方法2 环滁皆山也。其西南诸峰,林壑尤美,望之蔚然而深秀者,琅琊也。山行六七里,渐闻水声潺潺,而泻出于两峰之间者,酿泉也 ??????????????????????????????? ??????????????/????????????????? ............/................... .........................../... ??????????????????????????????? >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>> ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>/>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> dsdfsrc/Facades/OpenAI.php000064400000003315152665611430010520 0ustar00 $responses */ public static function fake(array $responses = []): OpenAIFake /** @phpstan-ignore-line */ { $fake = new OpenAIFake($responses); self::swap($fake); return $fake; } } src/Testing/OpenAIFake.php000064400000000161152665611430011372 0ustar00 $data */ public static function render(string $path, array $data = []): void { $contents = self::compile($path, $data); $existing = Termwind::getRenderer(); renderUsing(self::$output); try { render($contents); } finally { renderUsing($existing); } } /** * Compiles the given view. * * @param array $data */ private static function compile(string $path, array $data): string { extract($data); ob_start(); $path = str_replace('.', '/', $path); include sprintf('%s/../../resources/views/%s.php', __DIR__, $path); $contents = ob_get_contents(); ob_clean(); return (string) $contents; } } src/Commands/InstallCommand.php000064400000010206152665611430012522 0ustar00 'https://github.com/openai-php/laravel', 'OpenAI PHP Docs' => 'https://github.com/openai-php/client#readme', 'Join us on Telegram' => 'https://t.me/+66GDs6UM6RcxY2U8', ]; private const FUNDING_LINKS = [ 'Sponsor Sandro' => 'https://github.com/sponsors/gehrisandro', 'Sponsor Nuno' => 'https://github.com/sponsors/nunomaduro', ]; protected $signature = 'openai:install'; protected $description = 'Prepares the OpenAI client for use.'; public function handle(): void { View::renderUsing($this->output); View::render('components.badge', [ 'type' => 'INFO', 'content' => 'Installing OpenAI for Laravel.', ]); $this->copyConfig(); View::render('components.new-line'); $this->addEnvKeys('.env'); $this->addEnvKeys('.env.example'); View::render('components.new-line'); $wantsToSupport = $this->askToStarRepository(); $this->showLinks(); View::render('components.badge', [ 'type' => 'INFO', 'content' => 'Open your .env and add your OpenAI API key and organization id.', ]); if ($wantsToSupport) { $this->openRepositoryInBrowser(); } } private function copyConfig(): void { if (file_exists(config_path('openai.php'))) { View::render('components.two-column-detail', [ 'left' => 'config/openai.php', 'right' => 'File already exists.', ]); return; } View::render('components.two-column-detail', [ 'left' => 'config/openai.php', 'right' => 'File created.', ]); $this->callSilent('vendor:publish', [ '--provider' => ServiceProvider::class, ]); } private function addEnvKeys(string $envFile): void { if (! is_writable(base_path($envFile))) { View::render('components.two-column-detail', [ 'left' => $envFile, 'right' => 'File is not writable.', ]); return; } $fileContent = file_get_contents(base_path($envFile)); if ($fileContent === false) { return; } if (str_contains($fileContent, 'OPENAI_API_KEY')) { View::render('components.two-column-detail', [ 'left' => $envFile, 'right' => 'Variables already exists.', ]); return; } file_put_contents(base_path($envFile), PHP_EOL . 'OPENAI_API_KEY=' . PHP_EOL . 'OPENAI_ORGANIZATION=' . PHP_EOL, FILE_APPEND); View::render('components.two-column-detail', [ 'left' => $envFile, 'right' => 'OPENAI_API_KEY and OPENAI_ORGANIZATION variables added.', ]); } private function askToStarRepository(): bool { if (! $this->input->isInteractive()) { return false; } return $this->confirm(' Wanna show OpenAI for Laravel some love by starring it on GitHub?', false); } private function openRepositoryInBrowser(): void { if (PHP_OS_FAMILY == 'Darwin') { exec('open https://github.com/openai-php/laravel'); } if (PHP_OS_FAMILY == 'Windows') { exec('start https://github.com/openai-php/laravel'); } if (PHP_OS_FAMILY == 'Linux') { exec('xdg-open https://github.com/openai-php/laravel'); } } private function showLinks(): void { $links = [ ...self::LINKS, ...rand(0, 1) ? self::FUNDING_LINKS : array_reverse(self::FUNDING_LINKS, true), ]; foreach ($links as $message => $link) { View::render('components.two-column-detail', [ 'left' => $message, 'right' => $link, ]); } } } src/ServiceProvider.php000064400000004434152665611430011175 0ustar00app->singleton(ClientContract::class, static function (): Client { $apiKey = config('openai.api_key'); $organization = config('openai.organization'); $project = config('openai.project'); $baseUri = config('openai.base_uri'); if (! is_string($apiKey) || ($organization !== null && ! is_string($organization))) { throw ApiKeyIsMissing::create(); } $client = OpenAI::factory() ->withApiKey($apiKey) ->withOrganization($organization) ->withHttpHeader('OpenAI-Beta', 'assistants=v2') ->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)])); if (is_string($project)) { $client->withProject($project); } if (is_string($baseUri)) { $client->withBaseUri($baseUri); } return $client->make(); }); $this->app->alias(ClientContract::class, 'openai'); $this->app->alias(ClientContract::class, Client::class); } /** * Bootstrap any application services. */ public function boot(): void { if ($this->app->runningInConsole()) { $this->publishes([ __DIR__ . '/../config/openai.php' => config_path('openai.php'), ]); $this->commands([ InstallCommand::class, ]); } } /** * Get the services provided by the provider. * * @return array */ public function provides(): array { return [ Client::class, ClientContract::class, 'openai', ]; } } composer.json000064400000003277152665611430007310 0ustar00{ "name": "openai-php/laravel", "description": "OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API", "keywords": ["laravel","php", "openai", "sdk", "codex", "GPT-3", "DALL-E", "api", "client", "natural", "language", "processing"], "license": "MIT", "authors": [ { "name": "Nuno Maduro", "email": "enunomaduro@gmail.com" } ], "require": { "php": "^8.2.0", "guzzlehttp/guzzle": "^7.9.3", "laravel/framework": "^10", "openai-php/client": "^0.15.0" }, "require-dev": { "laravel/pint": "^1.22.0", "pestphp/pest": "^3.8.2|^4.0.0", "pestphp/pest-plugin-arch": "^3.1.1|^4.0.0", "phpstan/phpstan": "^1.12.25", "symfony/var-dumper": "^7.2.6" }, "autoload": { "psr-4": { "OpenAI\\Laravel\\": "src/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "minimum-stability": "dev", "prefer-stable": true, "config": { "sort-packages": true, "preferred-install": "dist", "allow-plugins": { "pestphp/pest-plugin": true, "php-http/discovery": true } }, "extra": { "laravel": { "providers": [ "OpenAI\\Laravel\\ServiceProvider" ] } }, "scripts": { "lint": "pint -v", "test:lint": "pint --test -v", "test:types": "phpstan analyse --ansi", "test:unit": "pest --colors=always", "test": [ "@test:lint", "@test:types", "@test:unit" ] } } LICENSE.md000064400000002111152665611430006154 0ustar00The MIT License (MIT) Copyright (c) Nuno Maduro Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. resources/views/components/new-line.php000064400000000014152665611430014333 0ustar00
resources/views/components/badge.php000064400000000642152665611430013666 0ustar00 ['blue', 'INFO'], 'ERROR' => ['red', 'ERROR'], }; ?>
resources/views/components/two-column-detail.php000064400000000514152665611430016166 0ustar00
config/openai.php000064400000003477152665611430010021 0ustar00 env('OPENAI_API_KEY'), 'organization' => env('OPENAI_ORGANIZATION'), /* |-------------------------------------------------------------------------- | OpenAI API Project |-------------------------------------------------------------------------- | | Here you may specify your OpenAI API project. This is used optionally in | situations where you are using a legacy user API key and need association | with a project. This is not required for the newer API keys. */ 'project' => env('OPENAI_PROJECT'), /* |-------------------------------------------------------------------------- | OpenAI Base URL |-------------------------------------------------------------------------- | | Here you may specify your OpenAI API base URL used to make requests. This | is needed if using a custom API endpoint. Defaults to: api.openai.com/v1 */ 'base_uri' => env('OPENAI_BASE_URL'), /* |-------------------------------------------------------------------------- | Request Timeout |-------------------------------------------------------------------------- | | The timeout may be used to specify the maximum number of seconds to wait | for a response. By default, the client will time out after 30 seconds. */ 'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30), ];