langfun
v0.1.1
安裝|入門|教程|不和諧社區
Langfun是一個有動力的圖書館,旨在使語言模型(LM)有趣。它的主要原則是通過將語言視為功能來實現自然語言和編程之間的無縫集成。通過引入面向對象的提示,LangFun可以使用對象和類型提示LLMS,從而提供增強的控制和簡化代理的開發。
要解鎖Langfun的魔力,您可以從Langfun 101開始。值得注意的是,Langfun與Gemini,GPT,GPT,Claude等流行的LLM兼容,而無需進行其他微調。
Langfun是強大而可擴展的:
Langfun簡單而優雅:
import langfun as lf
import pyglove as pg
from IPython import display
class Item ( pg . Object ):
name : str
color : str
class ImageDescription ( pg . Object ):
items : list [ Item ]
image = lf . Image . from_uri ( 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg' )
display . display ( image )
desc = lf . query (
'Describe objects in {{my_image}} from top to bottom.' ,
ImageDescription ,
lm = lf . llms . Gpt4o ( api_key = '<your-openai-api-key>' ),
my_image = image ,
)
print ( desc )輸出:
ImageDescription(
items = [
0 : Item(
name = 'Mercury',
color = 'Gray'
),
1 : Item(
name = 'Venus',
color = 'Yellow'
),
2 : Item(
name = 'Earth',
color = 'Blue and white'
),
3 : Item(
name = 'Moon',
color = 'Gray'
),
4 : Item(
name = 'Mars',
color = 'Red'
),
5 : Item(
name = 'Jupiter',
color = 'Brown and white'
),
6 : Item(
name = 'Saturn',
color = 'Yellowish-brown with rings'
),
7 : Item(
name = 'Uranus',
color = 'Light blue'
),
8 : Item(
name = 'Neptune',
color = 'Dark blue'
)
]
)
有關更多示例,請參見Langfun 101。
Langfun通過其他功能提供了一系列功能,使用戶只能安裝所需的功能。 Langfun的最小安裝只需要Pyglove,Jinja2和請求。要安裝LangFun的依賴性最小,請使用:
pip install langfun
有關所有依賴項的完整安裝,請使用:
pip install langfun[all]
要安裝夜間構建,請包括--pre標誌,例如:
pip install langfun[all] --pre
如果要自定義安裝,則可以使用langfun[X1, X2, ..., Xn]等軟件包名稱選擇特定功能,其中Xi對應於下面列表的標籤:
| 標籤 | 描述 |
|---|---|
| 全部 | 所有LangFun功能。 |
| LLM | 所有支持的LLMS。 |
| LLM-Google | 所有支持Google驅動的LLMS。 |
| LLM-Google-Genai | LLMS由Google Generative AI API提供動力 |
| 啞劇 | 所有啞劇支持。 |
| Mime-Auto | 自動MIME類型檢測。 |
| Mime-Docx | DOCX格式支持。 |
| Mime-Pil | 圖像支持PIL。 |
| mime-xlsx | XLSX格式支持。 |
| UI | UI增強 |
例如,要安裝包括Google驅動的LLM在內的每晚構建,完整的模式支持和UI增強功能,請使用:
pip install langfun[llm-google,mime,ui] --pre
免責聲明:這不是官方支持的Google產品。