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产品。