Marvin是一種輕巧的AI工具包,用於構建可靠,可擴展且易於信任的自然語言接口。
Marvin的每種工具都是簡單而自我記錄的,使用AI來解決常見但複雜的挑戰,例如實體提取,分類和生成合成數據。每個工具都是獨立的,可以逐步採用,因此您可以自行使用它們或與任何其他庫結合使用它們。 Marvin也是多模式的,支持圖像和音頻生成,並使用圖像作為提取和分類的輸入。
Marvin是針對更關心AI而不是建立AI的開發人員,我們專注於創造出色的開發人員體驗。 Marvin用戶應該有能力將緊密分割的“ AI Magic”帶入任何傳統軟件項目,並提供幾行代碼。
Marvin的目標是將可靠的,可觀察到的軟件與生成AI建立的最佳實踐合併為單個易於使用的庫。這是一個嚴肅的工具,但我們希望您對此有所樂趣。
Marvin是開源的,可以免費使用,並與?由隊長組成。
使用pip
安裝最新版本:
pip install marvin -U
要驗證您的安裝,請在終端中運行marvin version
。
Marvin由各種有用的工具組成,所有這些工具都旨在獨立使用。每個代表一個常見的LLM用例,並將其供電到簡單的自我文獻界面。
?在沒有源代碼的情況下編寫自定義AI功能的功能
?將文本分類為類別
?從文本中提取結構化實體
?將文本轉換為結構化數據
從模式中生成合成數據
?從文本或函數中創建圖像
用自然語言描述圖像
?將圖像分類為類別
?從圖像中提取結構化實體
?將圖像轉換為結構化數據
從文本或功能中產生語音
✍️從錄製的音頻中轉錄演講
?娘不斷錄製用戶或單個短語
?持續錄製視頻
?與助手聊天並使用自定義工具
?構建管理持續狀態的應用程序
這是Marvin的一些主要特徵的旋風之旅。有關更多信息,請檢查文檔!
Marvin可以使用一組標籤對文本classify
:
import marvin
marvin . classify (
"Marvin is so easy to use!" ,
labels = [ "positive" , "negative" ],
)
# "positive"
在此處了解有關分類的更多信息。
Marvin可以從文本中extract
結構化實體:
import pydantic
class Location ( pydantic . BaseModel ):
city : str
state : str
marvin . extract ( "I moved from NY to CHI" , target = Location )
# [
# Location(city="New York", state="New York"),
# Location(city="Chicago", state="Illinois")
# ]
幾乎所有Marvin功能都可以得到更多控制的instructions
。在這裡,我們僅提取貨幣價值:
marvin . extract (
"I paid $10 for 3 tacos and got a dollar and 25 cents back." ,
target = float ,
instructions = "Only extract money"
)
# [10.0, 1.25]
在此處了解有關實體提取的更多信息。
Marvin可以按照說明和可選架構為您generate
合成數據:
class Location ( pydantic . BaseModel ):
city : str
state : str
marvin . generate (
n = 4 ,
target = Location ,
instructions = "cities in the United States named after presidents"
)
# [
# Location(city='Washington', state='District of Columbia'),
# Location(city='Jackson', state='Mississippi'),
# Location(city='Cleveland', state='Ohio'),
# Location(city='Lincoln', state='Nebraska'),
# ]
在此處了解有關數據生成的更多信息。
Marvin可以將任意文本cast
到任何python類型:
marvin . cast ( "one two three" , list [ int ])
# [1, 2, 3]
這對於標準化文本輸入或將自然語言與模式匹配很有用:
class Location ( pydantic . BaseModel ):
city : str
state : str
marvin . cast ( "The Big Apple" , Location )
# Location(city="New York", state="New York")
對於基於班級的方法,可以將Marvin的@model
Decorator應用於任何Pydantic模型,以使其從文本進行實例化:
@ marvin . model
class Location ( pydantic . BaseModel ):
city : str
state : str
Location ( "The Big Apple" )
# Location(city="New York", state="New York")
在此處了解有關鑄造類型的更多信息。
MARVIN功能可讓您組合所有輸入,指令和輸出類型,以創建自定義AI驅動的行為...而無需源代碼。這些功能可以遠遠超出extract
或classify
的功能,並且非常適合將輸入輸入到輸出的複雜自然語言處理或映射組合。
@ marvin . fn
def sentiment ( text : str ) -> float :
"""
Returns a sentiment score for `text`
between -1 (negative) and 1 (positive).
"""
sentiment ( "I love working with Marvin!" ) # 0.8
sentiment ( "These examples could use some work..." ) # -0.2
Marvin功能看起來完全像常規Python功能,只是您不必編寫任何源代碼。當調用這些功能時,AI會解釋其描述並輸入並生成輸出。
請注意,Marvin無法通過生成或執行源代碼來工作,對於大多數用例而言,這將是不安全的。相反,它將LLM本身用作“運行時”來預測功能輸出。這實際上是其力量的來源:Marvin功能可以處理很難或不可能作為代碼表達的複雜用例。
您可以在此處了解有關功能的更多信息。
Marvin可以從文字中paint
圖像:
marvin . paint ( "a simple cup of coffee, still warm" )
在此處了解有關圖像生成的更多信息。
除文本外,Marvin還支持使用GPT-4 Vision Model從圖像中的字幕,分類,轉換和提取實體:
marvin . classify (
marvin . Image . from_path ( "docs/images/coffee.png" ),
labels = [ "drink" , "food" ],
)
# "drink"
Marvin可以轉錄語音並在開箱即用,但可選的audio
額外提供了用於錄製和播放音頻的實用程序。
import marvin
import marvin . audio
# record the user
user_audio = marvin . audio . record_phrase ()
# transcribe the text
user_text = marvin . transcribe ( user_audio )
# cast the language to a more formal style
ai_text = marvin . cast ( user_text , instructions = 'Make the language ridiculously formal' )
# generate AI speech
ai_audio = marvin . speak ( ai_text )
# play the result
ai_audio . play ()
功能想法?在我們的不和諧中的#development
頻道中分享。
?找到一個錯誤?隨意打開一個問題。
?回饋?馬文正在積極發展,我們很想听聽。