دفع GPT مع جناح اختبار يجعله يكتب رمزًا دقيقًا بشكل مثير للإعجاب
يعمل AITDD على BUN ، تأكد من تثبيت أحدث إصدار من BUN.
قم بتثبيت AITDD على مستوى العالم كـ CLI:
curl -sSL https://raw.githubusercontent.com/di-sukharev/AI-TDD/master/install.sh | bash
احصل على مفتاح API من Openai. تأكد من إضافة تفاصيل الدفع ، لذلك تعمل API.
اضبط المفتاح على تكوين AITDD:
aitdd config set OPENAI_API_KEY < your_api_key >
يتم تخزين مفتاح API الخاص بك محليًا في ملف التكوين ~/.aitdd/config
ولا يتم تخزينه في أي مكان بأي طريقة أخرى.
اضبط الأمر لتشغيل الاختبارات:
aitdd config set RUN_TESTS " npm run test "
يتم تخزين مفتاح API الخاص بك محليًا في ملف التكوين ~/.aitdd/config
ولا يتم تخزينه في أي مكان بأي طريقة أخرى.
فيما يلي مجموعة اختبار واجهة مكتوبة في مكتبة اختبار Jest +. نعم ، يجتاز AITDD بسهولة حتى اختبارات الواجهة الأمامية:
import React from "react" ;
import { rest } from "msw" ;
import { setupServer } from "msw/node" ;
import { render , fireEvent , waitFor , screen } from "@testing-library/react" ;
import "@testing-library/jest-dom" ;
import Fetch from "../fetch" ;
const server = setupServer (
rest . get ( "/greeting" , ( req , res , ctx ) => {
return res ( ctx . json ( { greeting : "hello there" } ) ) ;
} )
) ;
beforeAll ( ( ) => server . listen ( ) ) ;
afterEach ( ( ) => server . resetHandlers ( ) ) ;
afterAll ( ( ) => server . close ( ) ) ;
test ( "loads and displays greeting" , async ( ) => {
render ( < Fetch url = "/greeting" / > ) ;
fireEvent . click ( screen . getByText ( "Load Greeting" ) ) ;
await waitFor ( ( ) => screen . getByRole ( "heading" ) ) ;
expect ( screen . getByRole ( "heading" ) ) . toHaveTextContent ( "hello there" ) ;
expect ( screen . getByRole ( "button" ) ) . toBeDisabled ( ) ;
} ) ;
test ( "handles server error" , async ( ) => {
server . use (
rest . get ( "/greeting" , ( req , res , ctx ) => {
return res ( ctx . status ( 500 ) ) ;
} )
) ;
render ( < Fetch url = "/greeting" / > ) ;
fireEvent . click ( screen . getByText ( "Load Greeting" ) ) ;
await waitFor ( ( ) => screen . getByRole ( "alert" ) ) ;
expect ( screen . getByRole ( "alert" ) ) . toHaveTextContent ( "Oops, failed to fetch!" ) ;
expect ( screen . getByRole ( "button" ) ) . not . toBeDisabled ( ) ;
} ) ;
مستعد؟ فيما يلي الرمز الذي تم إنشاؤه بواسطة AITDD (GPT-4) لاجتياز الاختبار:
import React , { useState } from "react" ;
function Fetch ( { url } ) {
const [ data , setData ] = useState ( null ) ;
const [ error , setError ] = useState ( null ) ;
const [ loading , setLoading ] = useState ( false ) ;
async function fetchData ( ) {
setLoading ( true ) ;
try {
const response = await fetch ( url ) ;
if ( ! response . ok ) throw new Error ( "Failed to fetch" ) ;
const data = await response . json ( ) ;
setData ( data . greeting ) ;
} catch ( error ) {
setError ( error . message ) ;
} finally {
setLoading ( false ) ;
}
}
return (
< div >
{ data && < h1 role = "heading" > { data } < / h1 > }
{ error && < div role = "alert" > { error } < / div > }
< button onClick = { fetchData } disabled = { loading } >
Load Greeting
< / button >
< / div >
) ;
}
export default Fetch ;
يمكنك استدعاء AITDD مثل هذا:
aitdd run
أنت تدفع مقابل طلباتك الخاصة إلى Openai API. يستخدم AITDD أحدث طراز GPT افتراضيًا ، تحقق من تسعيره. يتم تعيين مميزات الاستجابة القصوى على 2000 ، يمكنك ضبطه عبر ait config set maxTokens=<number>
.
لم أستطع إدارة نموذج ChatGPT لحل المشكلة. حاولت القليل من الرصاص مع مثال على الرد ، فهو لا يفهم ما أريد. إذا كنت ترغب في محاولة إدارتها عبر chatgpt - اختبرها وفتح العلاقات العامة