async openai
v0.26.0
Openai的異步生鏽庫
async-openai是Openai的非正式鏽蝕庫。
該庫從環境變量OPENAI_API_KEY讀取API鍵。
# On macOS/Linux
export OPENAI_API_KEY= ' sk-... ' # On Windows Powershell
$ Env: OPENAI_API_KEY = ' sk-... 'async-openai目錄。僅實現用於實時API的類型,並且可以使用功能標誌realtime啟用。如果/當Openai發布官方規格時,這些類型可能會改變。
use async_openai :: {
types :: { CreateImageRequestArgs , ImageSize , ImageResponseFormat } ,
Client ,
} ;
use std :: error :: Error ;
# [ tokio :: main ]
async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
// create client, reads OPENAI_API_KEY environment variable for API key.
let client = Client :: new ( ) ;
let request = CreateImageRequestArgs :: default ( )
. prompt ( "cats on sofa and carpet in living room" )
. n ( 2 )
. response_format ( ImageResponseFormat :: Url )
. size ( ImageSize :: S256x256 )
. user ( "async-openai" )
. build ( ) ? ;
let response = client . images ( ) . create ( request ) . await ? ;
// Download and save images to ./data directory.
// Each url is downloaded and saved in dedicated Tokio task.
// Directory is created if it doesn't exist.
let paths = response . save ( "./data" ) . await ? ;
paths
. iter ( )
. for_each ( |path| println ! ( "Image file path: {}" , path.display ( ) ) ) ;
Ok ( ( ) )
}感謝您抽出寶貴的時間為項目做出貢獻和改進。我很高興有你!
歡迎所有形式的貢獻,例如新功能請求,錯誤修復,問題,文檔,測試,評論,示例等。
一個好的起點是查看現有的開放問題。
為了維持項目的質量,至少需要以下內容才是代碼貢獻:
該項目遵守生鏽的行為守則
該項目已根據MIT許可獲得許可。