superagent py
v0.2.40
Superagent 是一個開源框架,讓任何開發人員都可以在幾分鐘內將生產就緒的 AI 助理整合到任何應用程式中。
將此依賴項新增至專案的建置檔案:
pip install superagent-py
# or
poetry add superagent-py
from superagent . client import Superagent
client = Superagent ( token = "API_TOKEN" , base_url = "https://api.beta.superagent.sh" )
agent = client . agent . create ( request = {
"name" : "My Agent" ,
"description" : "My awesome agent" ,
"isActive" : True ,
"llmModel" : "GPT_4_1106_PREVIEW" ,
"prompt" : "You are a helpful assistant"
})
output = client . agent . invoke (
agent_id = agent . data . id ,
input = "Hi there!" ,
enable_streaming = False ,
session_id = "123"
)
print ( "Received response from superagent" , agent . data )
from superagent . client import AsyncSuperagent
agent = await client . agent . create ( request = {
"name" : "My Agent" ,
"description" : "My awesome agent" ,
"isActive" : True ,
"llmModel" : "GPT_4_1106_PREVIEW" ,
"prompt" : "You are a helpful assistant"
})
output = await client . agent . invoke (
agent_id = agent . data . id ,
input = "Hi there!" ,
enable_streaming = False ,
session_id = "123"
)
print ( "Received response from superagent" , agent . data )
SDK拋出的所有異常都會繼承moneykit.ApiError。
from superagent . core import ApiError
try :
client . agents . get ( agent_id = "12312" )
except APIError as e :
# handle any api related error
錯誤代碼如下:
狀態碼 | 錯誤類型 |
---|---|
第422章 | UnprocessableEntityError |
特別感謝 Fern 團隊對 Superagent 庫和 SDK 的所有支援❤️。
此 SDK 處於測試階段,版本之間可能會發生重大更改,而無需進行重大版本更新。因此,我們建議將套件版本固定到 pyproject.toml 檔案中的特定版本。這樣,您每次都可以安裝相同的版本,而不會破壞更改,除非您有意尋找最新版本。
雖然我們重視對此 SDK 的開源貢獻,但該程式庫是透過程式設計方式產生的。直接對該庫進行的新增必須移至我們的生成程式碼中,否則它們將在下一個生成的版本中被覆蓋。請隨意打開 PR 作為概念證明,但要知道我們無法按原樣合併它。我們建議先打開一個問題與我們討論!
另一方面,我們始終非常歡迎對自述文件做出貢獻!