การแจ้งให้ GPT พร้อมชุดทดสอบทำให้รหัสเขียนถูกต้องอย่างน่าประทับใจ
AITDD ทำงานบน BUN ตรวจสอบให้แน่ใจว่าคุณติดตั้งเวอร์ชัน BUN ล่าสุดก่อน
ติดตั้ง AITDD ทั่วโลกเป็น CLI:
curl -sSL https://raw.githubusercontent.com/di-sukharev/AI-TDD/master/install.sh | bash
รับคีย์ API ของคุณจาก OpenAI ตรวจสอบให้แน่ใจว่าคุณเพิ่มรายละเอียดการชำระเงินดังนั้น API จึงทำงานได้
ตั้งค่าปุ่มเป็น AITDD config:
aitdd config set OPENAI_API_KEY < your_api_key >
คีย์ API ของคุณถูกเก็บไว้ในเครื่องใน ~/.aitdd/config
config และไม่ได้เก็บไว้ที่ใดก็ได้ในวิธีอื่น
ตั้งค่าคำสั่งให้เรียกใช้การทดสอบ:
aitdd config set RUN_TESTS " npm run test "
คีย์ API ของคุณถูกเก็บไว้ในเครื่องใน ~/.aitdd/config
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 - ทดสอบและเปิด PR