
Yahoo Finance API – 完整指南
在開始本教程之前,請確保滿足以下前提條件:
每次調用AI都會消耗一定的費用,例如,本文所需的所有運行成本約為1英鎊(GBP)。
完成準備工作后,按照以下步驟設置項目環境:
克隆smol-developer項目到本地并進入項目目錄:
git clone https://github.com/smol-ai/developer
cddeveloper
使用pip安裝Python依賴項:
pipinstall-rrequirements.txt
將OpenAI API密鑰導出為環境變量:
export OPENAI_API_KEY=
測試環境是否配置正確:
python3 main_no_modal.py "a simple hello world application written in nodejs"
運行上述命令后,smol-developer工具將根據輸入提示生成初始代碼文件,例如一個簡單的index.js
文件,內容為“Hello, World!”的控制臺日志輸出。
在要求AI生成代碼之前,明確的需求定義至關重要。AI工具可以根據規范填補空白,但不完整或模糊的規范可能導致意外輸出。因此,建議采用迭代的方式逐步完善規范,每次修改后通過AI工具驗證效果。
在項目根目錄下創建一個名為my-prompt.md
的Markdown文件,內容如下:
"""
Create a RESTful CRUD API using express.js.
## Resources
The API has the following resources and fields:
### User
- id
- name
### Ticket
- id
- summary
- description
- author_id
### Comment
- id
- content
- author_id
- ticket_id
- parent_id
"""
運行以下命令讓AI生成代碼:
python3 main_no_modal.py my-prompt.md
生成的代碼可能會因工具的非確定性特性而有所不同,但整體流程應保持一致。生成的文件通常包括index.js
及其他相關文件。
初始生成的代碼可能包含不必要的驗證邏輯和數據庫配置。為此,更新規范以移除這些內容:
"""
Create a RESTful CRUD API using express.js.
## Resources
The API has the following resources and fields:
### User
- id
- name
### Ticket
- id
- summary
- description
- author_id
### Comment
- id
- content
- author_id
- ticket_id
- parent_id
## Adjustments
- Do not validate requests or responses
- Do not use a database, just use an array as a datastore for now
"""
運行AI工具后,生成的代碼將更符合簡化需求,例如使用數組作為數據存儲。盡管如此,生成的代碼可能仍包含未使用的導入或不匹配的函數調用。
為進一步提高代碼一致性和可維護性,可以在規范中明確模塊結構和文件內容。例如:
## Module structure
Each module (users, tickets, and comments) should use the following structure. "User" is used as an example, and the name should be changed appropriately for each given module.
- modules
- users
- userRoutes.js
- userController.js
- userService.js
### userRoutes.js
This file should be used in the index.js
like so:
```javascript
app.use('/users',userRoutes);
The file itself should contain mappings between a given endpoint and the controller method that serves it, like this:
router.get('/',userController.getAllUsers);
router.get('/:id',userController.getUserById);
router.[post](http://www.dlbhg.com/provider/uid2024120814472139bfa9)('/',userController.createUser);
router.put('/:id',userController.updateUser);
router.delete('/:id',userController.deleteUser);
This file should serve as an HTTP adapter, and should invoke business logic from the userService
. This file should declare the following functions:
This file should house the business logic for the module. This file will declare the following functions:
通過增加模塊化結構的詳細說明,生成的代碼將更符合預期。
AI生成代碼的非確定性可能導致每次運行結果不同,尤其在反復修改規范時,這會增加調試難度。
AI工具在生成代碼時可能忽略上下文,導致模塊之間不一致或調用錯誤。例如,生成的函數簽名可能與調用處不匹配。
目前缺乏標準化的描述語言來明確傳達需求,這使得生成的代碼質量在很大程度上依賴于提示的清晰度和AI的理解能力。
本文展示了如何利用AI工具(如smol-developer)快速生成API代碼,并通過迭代優化規范以提高代碼質量。盡管AI工具在代碼生成方面展現了強大的潛力,但其非確定性、上下文局限性和一致性問題表明,它們尚未完全適合生產環境。然而,隨著技術的不斷進步,這些問題有望逐步得到解決。
在此過程中,開發者應結合傳統工具(如Tyk API網關)以確保API開發的穩定性和可靠性。Tyk提供了全面的功能支持,包括身份驗證、速率限制和日志記錄,是構建高質量API的理想選擇。
原文鏈接: https://tyk.io/blog/using-ai-for-api-design/
Yahoo Finance API – 完整指南
WordPress REST API 內容注入漏洞分析
四款AI大模型API價格對比:DeepSeek R1、ChatGPT o3-mini、Grok3、通義千問 Max
四款AI大模型API基礎參數、核心性能的區別:DeepSeek R1、ChatGPT o3-mini、Grok3、通義千問 Max
2025年多模態大模型API基礎參數、核心性能:Deepseek、ChatGPT、文心一言
2025年最新推理大模型API價格對比:通義千問Max vs 豆包1.5 Pro vs 混元Lite
大模型新基座,基于FastAPI,利用Python開發MCP服務器
DeepSeek+ima:打造高效個人知識庫,提升學習與工作效率
快速接入騰訊地圖MCP Server