# 功能製造器 (Function Fabricator)
功能製造器是一個將自然語言描述轉換為 Python 函數的 AI 代理。通過提供清晰且詳細的要求,使用者可以生成遵循最佳實踐的代碼,包括必要的驗證,並有效處理邊界情況。該代理還會在代碼中添加註釋,使開發人員更容易理解實現背後的邏輯。這個工具非常適合希望自動化函數創建的初學程式員以及尋求簡化編碼過程的經驗豐富的開發人員。
# 開始使用
要開始使用,請確保您已經複製了 功能製造器。請按照 從模板創建 的指示複製並配置您的 AI 代理。
# 配置說明
# 知識
您可以上傳.pdf
或.txt
文件,為代理提供滿足您特定需求的量身定制背景。
# 用戶輸入
這個 AI 代理不需要輸入欄位。
# AI 模型
默認模型為 Llama 3.1 8B Instruct,但您還可以探索其他支持的AI模型。如果需要,請根據您的需要調整提示以獲得更精確的輸出。
TIP
有關配置 AI 代理的更詳細說明,請參閱 配置 AI 代理。
# 輸入與輸出範例
# 輸入範例
Here is the sample input.
Create a function called `calculate_area` that takes the radius of a circle as input and returns the area. Ensure the function handles negative radius inputs by returning None.
# Sample Output
Here is the sample output.
def calculate_area(radius):
"""
Calculate the area of a circle given its radius.
Parameters:
radius (float): The radius of the circle. Must be non-negative.
Returns:
float: The area of the circle if radius is valid, otherwise None.
"""
if radius < 0:
return None # Return None for negative radius
import math
area = math.pi * (radius ** 2)
return area
# 有效配置的提示
- 具體描述:清楚描述函數的目的、輸入和預期輸出以獲得最佳結果。
- 處理邊界情況:提及任何應考慮的邊界情況,例如無效輸入或特殊條件。
- 請求註釋:要求生成代碼中的註釋,以提高可讀性和可維護性。
- 測試輸出:生成函數後,使用各種輸入進行測試,以確保其行為如預期。
- 迭代提示:如果輸出不令人滿意,請完善提示並再次嘗試以獲得更好的結果。
# 相關文章
繼續探索我們的 代理模板庫,發現更多 AI 代理的實用範例!