本教學示範使用 LLMOps 最佳實務建構可用於生產的 AI 拉取請求審核器。 最終應用程式可在此處訪問,接受公共 PR URL 並返回人工智慧生成的評論。
應用概述
本教學涵蓋:
- 程式碼開發:從 GitHub 檢索 PR 差異並利用 LiteLLM 進行 LLM 互動。
- 可觀察性: 實現 Agenta 以進行應用程式監控和調試。
- 提示工程:使用 Agenta 的遊樂場迭代提示和模型選擇。
- 法學碩士評估:聘請法學碩士作為法官進行及時和模型評估。
- 部署:將應用程式部署為 API 並使用 v0.dev 建立簡單的 UI。
核心邏輯
AI 助理的工作流程很簡單:給定 PR URL,它從 GitHub 檢索差異並將其提交給 LLM 進行審核。
GitHub 差異可透過以下方式存取:
<code>https://patch-diff.githubusercontent.com/raw/{owner}/{repo}/pull/{pr_number}.diff</code>
這個 Python 函數取得差異:
def get_pr_diff(pr_url): # ... (Code remains the same) return response.text
LiteLLM 促進了 LLM 交互,在不同提供者之間提供一致的介面。
prompt_system = """ You are an expert Python developer performing a file-by-file review of a pull request. You have access to the full diff of the file to understand the overall context and structure. However, focus on reviewing only the specific hunk provided. """ prompt_user = """ Here is the diff for the file: {diff} Please provide a critique of the changes made in this file. """ def generate_critique(pr_url: str): diff = get_pr_diff(pr_url) response = litellm.completion( model=config.model, messages=[ {"content": config.system_prompt, "role": "system"}, {"content": config.user_prompt.format(diff=diff), "role": "user"}, ], ) return response.choices[0].message.content
使用 Agenta 實現可觀察性
Agenta 增強了可觀察性,追蹤輸入、輸出和資料流,以便於偵錯。
初始化 Agenta 並配置 LiteLLM 回呼:
import agenta as ag ag.init() litellm.callbacks = [ag.callbacks.litellm_handler()]
帶有 Agenta 裝飾器的儀器函數:
@ag.instrument() def generate_critique(pr_url: str): # ... (Code remains the same) return response.choices[0].message.content
設定AGENTA_API_KEY
環境變數(從Agenta取得)和可選的AGENTA_HOST
用於自架。
創建法學碩士遊樂場
Agenta 的自訂工作流程功能為迭代開發提供了類似 IDE 的遊樂場。 以下程式碼片段演示了與 Agenta 的配置和整合:
from pydantic import BaseModel, Field from typing import Annotated import agenta as ag import litellm from agenta.sdk.assets import supported_llm_models # ... (previous code) class Config(BaseModel): system_prompt: str = prompt_system user_prompt: str = prompt_user model: Annotated[str, ag.MultipleChoice(choices=supported_llm_models)] = Field(default="gpt-3.5-turbo") @ag.route("/", config_schema=Config) @ag.instrument() def generate_critique(pr_url:str): diff = get_pr_diff(pr_url) config = ag.ConfigManager.get_from_route(schema=Config) response = litellm.completion( model=config.model, messages=[ {"content": config.system_prompt, "role": "system"}, {"content": config.user_prompt.format(diff=diff), "role": "user"}, ], ) return response.choices[0].message.content
使用 Agenta 進行服務和評估
- 執行
agenta init
並指定應用程式名稱和 API 金鑰。 - 運行
agenta variant serve app.py
。
這使得應用程式可以透過 Agenta 的遊樂場進行存取以進行端到端測試。 LLM-as-a-judge用於評估。 評估者提示為:
<code>You are an evaluator grading the quality of a PR review. CRITERIA: ... (criteria remain the same) ANSWER ONLY THE SCORE. DO NOT USE MARKDOWN. DO NOT PROVIDE ANYTHING OTHER THAN THE NUMBER</code>
評估器的使用者提示:
<code>https://patch-diff.githubusercontent.com/raw/{owner}/{repo}/pull/{pr_number}.diff</code>
部署與前端
部署是透過 Agenta 的 UI 完成的:
- 導航到概述頁面。
- 點選所選變體旁的三個點。
- 選擇「部署到生產」。
v0.dev 前端用於快速 UI 建立。
後續步驟與結論
未來的改進包括及時細化、合併完整的程式碼上下文以及處理大的差異。 本教學成功示範了使用 Agenta 和 LiteLLM 建置、評估和部署生產就緒的 AI 拉取請求審閱器。
以上是使用 vev、litellm 和 Agenta 建立 AI 程式碼審查助手的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。

toAccesselementsInapythonlist,useIndIndexing,負索引,切片,口頭化。 1)indexingStartSat0.2)否定indexingAccessesessessessesfomtheend.3)slicingextractsportions.4)iterationerationUsistorationUsisturessoreTionsforloopsoreNumeratorseforeporloopsorenumerate.alwaysCheckListListListListlentePtotoVoidToavoIndexIndexIndexIndexIndexIndExerror。

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3漢化版
中文版,非常好用

WebStorm Mac版
好用的JavaScript開發工具