ข้ามไปที่เนื้อหาหลัก

สร้าง Open AI ใน Laravel อย่างไร #อ่านบทควทม


 1. สร้างตัวอย่าง chatbot จาก Telegram และ botman

2. สมัครใช้งาน bot 

3. ระบบหลังบ้าน

4. ทดสอบและใช้งาน

  1. ติดตั้ง composer require openai-php/laravel
  2. แก้ไขและเพิ่ท vendor php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
  3. ใส่ open ai keyในไฟล์ config/openai.php OPENAI_API_KEY=sk-...
  4. เรียกใช้งาน 
 use OpenAI\Laravel\Facades\OpenAI;
$result = OpenAI::completions()->create([

        'model' => 'text-davinci-003',
          'prompt' => 'PHP is',
      ]);
        echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.

        ส่วนของ Client

        ติดตั้ง
        composer require openai-php/client
        composer require guzzlehttp/guzzle

        เรียกใช่
        $yourApiKey = getenv('YOUR_API_KEY');
        $client = OpenAI::client($yourApiKey);

        $result = $client->completions()->create([
            'model' => 'text-davinci-003',
            'prompt' => 'PHP is',
        ]);

        echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.

        ส่วนเรียกใช้ client


        $yourApiKey = getenv('YOUR_API_KEY');

        $client = OpenAI::factory()
            ->withApiKey($yourApiKey)
            ->withOrganization('your-organization') // default: null
            ->withBaseUri('openai.example.com/v1') // default: api.openai.com/v1
            ->withHttpClient($client = new \GuzzleHttp\Client([])) // default: HTTP client found using PSR-18 HTTP Client Discovery
            ->withHttpHeader('X-My-Header', 'foo')
            ->withQueryParam('my-param', 'bar')
            ->withStreamHandler(fn (RequestInterface $request): ResponseInterface => $client->send($request, [
                'stream' => true // Allows to provide a custom stream handler for the http client.
            ]))
            ->make();

        เรียกใช้ แสดงรายการ Model


        $response = $client->models()->list();

        $response->object; // 'list'

        foreach ($response->data as $result) {
            $result->id; // 'text-davinci-003'
            $result->object; // 'model'
            // ...
        }

        $response->toArray(); // ['object' => 'list', 'data' => [...]]

        ค้นคืน retrieve
        $response = $client->models()->retrieve('text-davinci-003');

        $response->id; // 'text-davinci-003'
        $response->object; // 'model'
        $response->created; // 1642018370
        $response->ownedBy; // 'openai'
        $response->root; // 'text-davinci-003'
        $response->parent; // null

        foreach ($response->permission as $result) {
            $result->id; // 'modelperm-7E53j9OtnMZggjqlwMxW4QG7' 
            $result->object; // 'model_permission' 
            $result->created; // 1664307523 
            $result->allowCreateEngine; // false 
            $result->allowSampling; // true 
            $result->allowLogprobs; // true 
            $result->allowSearchIndices; // false 
            $result->allowView; // true 
            $result->allowFineTuning; // false 
            $result->organization; // '*' 
            $result->group; // null 
            $result->isBlocking; // false 
        }

        $response->toArray(); // ['id' => 'text-davinci-003', ...]

        ลบ model
        $response = $client->models()->delete('curie:ft-acmeco-2021-03-03-21-44-20');

        $response->id; // 'curie:ft-acmeco-2021-03-03-21-44-20'
        $response->object; // 'model'
        $response->deleted; // true

        $response->toArray(); // ['id' => 'curie:ft-acmeco-2021-03-03-21-44-20', ...]

        ความคิดเห็น

        โพสต์ยอดนิยมจากบล็อกนี้

        Anvil แฟลต์ฟอร์ม สำหรับ Python Full Stack มีครบ จบในเครื่องมือเดียว

        Anvil แฟลต์ฟอร์ม สำหรับ Python Full Stack มีครบ จบในเครื่องมือเดียว Avil เป็นแฟลต์ฟอร์มสำหรับสร้างเว็บแอพลิเคชั่น ด้วยภาษา python สามารถใช้งานทั้ง HTML CSS JavaScript SQL ทั้งหมดนี้รวมในเครื่องมือที่ชื่อว่า Anvil Python ใช้สำหรับรันบนบราวเซอร์ เซอร์เวิรส์ และสร้าง UI ด้วยวิธีการ Drag-and-Drop เพียงลากวาง UK และยังสามารถเชื่อมต่อและใช้งาน Database  และยังสามารถ Integration กับแฟลต์ฟอร์มอื่นๆ ได้อีกด้วย โครงสร้างของ Anvil  การออกแบบง่ายๆ ด้วย drag-and-drop ใช้ python เป็น client-side และรันบน บราวเซอร์ Server-side รันบน Anvil Server สามารถใช้ Database ต่างๆ เพื่อเก็บข้อมูล สามารถรัน python บนเครื่องและตอบโต้กับแอปพลิเคขั่นไดด้

        TomCat สำหรับติดตั้ง แก้ไข คอนฟิก ใช้งาน JSP

        Apache Tomcat เป็น  HTTP Server ที่มีความสามารถนำภาษาจาวามาใช้งานได้  สามารถใช้เทคโนโลยีของภาษาจาวาที่เรียกว่า Java Servlet  และ Java Server Page (JSP)  Tomcat เป็นโปรแกรม Open-Source  อยู่ภายใต้การดูแลของ Apache Software Foundation  (ซึ่งเป็นผู้สร้าง Apache HTTP Server ที่เป็นที่นิยมใช้กันอย่างแพร่หลาย)  สามารถอ่านรายละเอียดของ Tomcat ได้ที่  http://tomcat.apache.org  โดยเลือกหัวข้อ “ Documentation”  และเลือก “Tomcat 7.0” ขั้นตอนการติดตั้ง Tomcat เรียงลำดับดังนี้

        10 Game Engine สำหรับการพัฒนาโปรแกรมเกมส์ด้วยที่ทรงประสิทธิภาพ

        เอ็นจิ้นเกม (Game Engine )คืออะไร  เอ็นจิ้นเกม game คือ เฟรมเวิร์กซอฟต์แวร์ที่ใช้ในการพัฒนาวิดีโอเกม พูดง่ายๆ คือ เครื่องมือสำหรับการเขียนโค้ดในการสร้างวิดีโอเกม ช่วยแก้ปัญหาที่ต้องจัดการกับการเรนเดอร์กราฟิก Render ตลอดจนใช้จัดการกับข้อมูลของผู้ใช้ หรือการนำกฎต่างๆ ฟิสิกส์ไปใช้ในโลกของเกม สิ่งเหล่านี้ (และอื่น ๆ ) เป็นข้อกังวลและข้อจำกัดในการพัฒนาเกมส์ที่เอ็นจิ้นเกมมาช่วยจัดการให้ เพื่อปรับปรุงกระบวนการพัฒนาให้มีประสิทธิภาพ โดยมอบโค้ดและเครื่องมือที่นำมาใช้ซ้ำให้กับผู้เขียนโค้ดได้ แทนที่จะเขียนโค้ดทุกอย่างตั้งแต่เริ่มต้น เอ็นจิ้นเกมช่วยให้ผู้เขียนโค้ดมุ่งความสนใจไปที่การออกแบบการเล่นเกมและสร้างประสบการณ์ที่ไม่เหมือนใคร โดยรวมแล้ว เอ็นจิ้นเกมที่คุณเลือกจะส่งผลต่อแพลตฟอร์มเกม เช่นเดียวกับเกมที่คุณสร้าง เครื่องยนต์แต่ละตัวมีคุณสมบัติ จุดแข็ง และจุดอ่อนที่แตกต่างกัน ดังนั้นการเลือกเครื่องยนต์ให้เหมาะสมจึงเป็นสิ่งสำคัญ เอ็นจิ้นเกมยอดนิยมที่นักพัฒนาใช้ในปัจจุบัน ได้แก่ Unity, Unreal Engine และ Godot 1. Unity Unity เป็น Game Engine หนึ่ง หรือเครื่องมือสำหรับนักพัฒนาเกมได้ทั้งรูปแบบ 2 มิต...