Upgrade to Pro — share decks privately, control downloads, hide ads and more …

生成式 AI CodeGPT 開發經驗談

Bo-Yi Wu
November 08, 2023

生成式 AI CodeGPT 開發經驗談

議程網址: https://modernweb.tw/2023/session-page/2428

相信大家對 ChatGPT 不會很陌生,這是目前在生成式人工智慧 (AIGC: AI Generated Content) 內的當紅炸子雞,然而 ChatGPT 對於軟體工程師有什麼影響呢?能否透過 ChatGPT 改善團隊流程或協助開發?而我現在想到最直接的就是用 ChatGTP 幫忙寫 Git Commit Message,然而怎麼把 Commit Message 寫好可以參考這篇文章,為了能達成這目的,我用 Go 語言寫了一個 CLI 工具 CodeGPT (請大家幫忙分享),來協助軟體工程師整理開發內容

Bo-Yi Wu

November 08, 2023
Tweet

More Decks by Bo-Yi Wu

Other Decks in Technology

Transcript

  1. ⽣成式 AI ⼯具


    CodeGPT 開發經驗談
    Bo-Yi Wu


    2023/11/08


    ModernWeb in Taipei

    View full-size slide

  2. https:
    / /
    github.com/appleboy/CodeGPT

    View full-size slide

  3. About me (Mediatek)
    • Maintain Drone CI/CD Plugin (15)


    • Member of Gitea Platform


    • Member of Gin Golang Framework


    • Maintain GitHub Actions Plugins (18).

    View full-size slide

  4. ⼤綱
    • 開發動機 (Motivation)


    • 專案介紹 (Introduction)


    • 擴⼤範圍 (Scale of Scope)


    • 實際操作 (Live Demo)

    View full-size slide

  5. 開發者必備


    ⽣成式 AI ⼯具
    $IBU(15 (JU)VC$PQJMPU

    View full-size slide

  6. 開發動機

    View full-size slide

  7. 1. 個⼈需求


    (Personal)

    View full-size slide

  8. 2. 團隊需求


    (Security)

    View full-size slide

  9. ࢖༻؀ڥෆಉ
    ࿈ઢ҆શސྀ

    View full-size slide

  10. ࢖༻؀ڥෆಉ
    ࿈ઢ҆શސྀ

    View full-size slide

  11. 專案介紹

    View full-size slide

  12. IUUQTPQFOBJDPNCMPHOFXNPEFMTBOEEFWFMPQFSQSPEVDUTBOOPVODFEBUEFWEBZ

    View full-size slide

  13. 1SJDJOH අ༻

    IUUQTPQFOBJDPNQSJDJOH

    View full-size slide

  14. https:
    / /
    github.com/appleboy/CodeGPT/releases

    View full-size slide

  15. Using OpenAI Key

    View full-size slide

  16. All conf
    i
    g setting

    View full-size slide

  17. Using Azure OpenAI Key

    View full-size slide

  18. Generate Commit Message

    View full-size slide

  19. IUUQTHJUIVCDPNBQQMFCPZ$PEF(15JTTVFT
    4VQQPSU$POWFOUJPOBM$PNNJUT

    View full-size slide

  20. (FOFSBUF%FTDSJQUJPO
    (FOFSBUF5JUMF
    (FOFSBUF5ZQF

    View full-size slide

  21. IUUQTHJUIVCDPNBQQMFCPZ$PEF(15JTTVFT
    4VQQPSU$PNNJU.FTTBHFGPSNBU

    View full-size slide

  22. ࣗగ5FNQMBUF֨ࣜ

    View full-size slide

  23. ࢧԉ٬੡ԽᏓᏐ

    View full-size slide

  24. *ODPSSFDU$PNNJU4VNNBSZGPSNBU
    IUUQTHJUIVCDPNBQQMFCPZ$PEF(15JTTVFT

    View full-size slide

  25. Function Call


    (Before 2023/11/06)

    View full-size slide

  26. 5PPMT5PPM$IPJDF BGUFS

    IUUQTCJUMZ2-R$'&

    View full-size slide

  27. 擴⼤範圍

    View full-size slide

  28. 如何推動其他部⾨


    (SWRD ~ 1w ⼈)

    View full-size slide

  29. "VUIPSJ[BUJPO'MPX
    96TFS*%
    +855PLFO

    View full-size slide

  30. 計算問與答


    Token Count


    (每⼈每天上限 xxxx 台幣)

    View full-size slide

  31. "VUIPSJ[BUJPO'MPX

    View full-size slide

  32. 1.Send JWT Token and User ID


    2.Check User Permission


    3.Send Request to Azure OpenAI

    View full-size slide

  33. CLI 如何拿到


    User ID


    (X-User-ID)

    View full-size slide

  34. 1SPYZ0"VUI (JUFB4FSWJDF

    View full-size slide

  35. auth
    : =
    &oauth2.Conf
    i
    g{


    ClientID
    :
    CLIENT_ID,


    ClientSecret: CLIENT_SECRET,


    RedirectURL
    :
    "http:
    / /
    localhost:9999/callback",


    Scopes: []string{"openid", "prof
    i
    le", "email"},


    Endpoint: oauth2.Endpoint{


    AuthURL
    :
    GITEA_SERVER + "/login/oauth/authorize",


    TokenURL
    :
    GITEA_SERVER + "/login/oauth/access_token",


    },


    }


    View full-size slide

  36. apiKey
    : =
    c.GetHeader("api
    -
    key")


    if apiKey
    = =
    "" {


    apiKey = strings.TrimPref
    i
    x(c.GetHeader("Authorization"), "Bearer ")


    }


    if apiKey
    = =
    "" {


    c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": gin.H{


    "code": strconv.Itoa(http.StatusUnauthorized),


    "message": "missing authorization header or api key",


    }})


    return


    }


    claims, err
    : =
    oauth.ParseToken(apiKey)


    if err
    ! =
    nil {


    c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": gin.H{


    "code": strconv.Itoa(http.StatusUnauthorized),


    "message": err.Error(),


    }})


    return


    }


    / /
    Set the X-User-Id header to the account id from the JWT claims.


    c.Request.Header.Set("X-User-Id", claims.Account)


    / /
    Set the api
    -
    key header to the api key from the specif
    i
    c API key.


    c.Request.Header.Set("api
    -
    key", cfg.API.Key)




    View full-size slide

  37. (FU6TFS*%BOE5PLFO
    3FQMBDF6TFS5PLFO8JUI1SPKFDU5PLFO
    4FOE6TFS*%BOE1SPKFDU5PLFO
    $IFDL6TFS*%1FSNJTTJPO
    4FOE0QFO"*3FRVFTUBOE-PH

    View full-size slide

  38. 實際操作

    View full-size slide