<div align="center">
<img src="https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg" width="520px" alt="logo"></img>
</div>
# Langfun
[![PyPI version](https://badge.fury.io/py/langfun.svg)](https://badge.fury.io/py/langfun)
[![codecov](https://codecov.io/gh/google/langfun/branch/main/graph/badge.svg)](https://codecov.io/gh/google/langfun)
![pytest](https://github.com/google/langfun/actions/workflows/ci.yaml/badge.svg)
[**Installation**](#install) | [**Getting started**](#hello-langfun) | [**Tutorial**](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb)
## Introduction
Langfun is a [PyGlove](https://github.com/google/pyglove) powered library that
aims to *make language models (LM) fun to work with*. Its central principle is
to enable seamless integration between natural language and programming by
treating language as functions. Through the introduction of *Object-Oriented Prompting*,
Langfun empowers users to prompt LLMs using objects and types, offering enhanced
control and simplifying agent development.
To unlock the magic of Langfun, you can start with
[Langfun 101](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb). Notably, Langfun is compatible with popular LLMs such as Gemini, GPT,
Claude, all without the need for additional fine-tuning.
## Why Langfun?
Langfun is *powerful and scalable*:
* Seamless integration between natural language and computer programs.
* Modular prompts, which allows a natural blend of texts and modalities;
* Efficient for both request-based workflows and batch jobs;
* A powerful eval framework that thrives dimension explosions.
Langfun is *simple and elegant*:
* An intuitive programming model, graspable in 5 minutes;
* Plug-and-play into any Python codebase, making an immediate difference;
* Comprehensive LLMs under a unified API: Gemini, GPT, Claude, Llama3, and more.
* Designed for agile developement: offering intellisense, easy debugging, with minimal overhead;
## Hello, Langfun
```python
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)
```
*Output:*
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg" width="520px" alt="my_image"></img>
```
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'
)
]
)
```
See [Langfun 101](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb) for more examples.
## Install
```
pip install langfun
```
Or install nightly build with:
```
pip install langfun --pre
```
*Disclaimer: this is not an officially supported Google product.*
Raw data
{
"_id": null,
"home_page": "https://github.com/google/langfun",
"name": "langfun",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "llm generative-ai machine-learning",
"author": "Langfun Authors",
"author_email": "langfun-authors@google.com",
"download_url": "https://files.pythonhosted.org/packages/e4/13/887945729c5ef622949cb8ddc04c72d1534dcaed5aea4bf8f27638aa0b0c/langfun-0.1.1.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n<img src=\"https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg\" width=\"520px\" alt=\"logo\"></img>\n</div>\n\n# Langfun\n\n[![PyPI version](https://badge.fury.io/py/langfun.svg)](https://badge.fury.io/py/langfun)\n[![codecov](https://codecov.io/gh/google/langfun/branch/main/graph/badge.svg)](https://codecov.io/gh/google/langfun)\n![pytest](https://github.com/google/langfun/actions/workflows/ci.yaml/badge.svg)\n\n[**Installation**](#install) | [**Getting started**](#hello-langfun) | [**Tutorial**](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb)\n\n## Introduction\n\nLangfun is a [PyGlove](https://github.com/google/pyglove) powered library that\naims to *make language models (LM) fun to work with*. Its central principle is\nto enable seamless integration between natural language and programming by\ntreating language as functions. Through the introduction of *Object-Oriented Prompting*, \nLangfun empowers users to prompt LLMs using objects and types, offering enhanced\ncontrol and simplifying agent development.\n\nTo unlock the magic of Langfun, you can start with\n[Langfun 101](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb). Notably, Langfun is compatible with popular LLMs such as Gemini, GPT,\nClaude, all without the need for additional fine-tuning.\n\n## Why Langfun?\n\nLangfun is *powerful and scalable*:\n\n* Seamless integration between natural language and computer programs.\n* Modular prompts, which allows a natural blend of texts and modalities;\n* Efficient for both request-based workflows and batch jobs;\n* A powerful eval framework that thrives dimension explosions.\n\nLangfun is *simple and elegant*:\n\n* An intuitive programming model, graspable in 5 minutes;\n* Plug-and-play into any Python codebase, making an immediate difference;\n* Comprehensive LLMs under a unified API: Gemini, GPT, Claude, Llama3, and more.\n* Designed for agile developement: offering intellisense, easy debugging, with minimal overhead;\n\n## Hello, Langfun\n\n```python\nimport langfun as lf\nimport pyglove as pg\n\nfrom IPython import display\n\nclass Item(pg.Object):\n name: str\n color: str\n\nclass ImageDescription(pg.Object):\n items: list[Item]\n\nimage = lf.Image.from_uri('https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg')\ndisplay.display(image)\n\ndesc = lf.query(\n 'Describe objects in {{my_image}} from top to bottom.',\n ImageDescription,\n lm=lf.llms.Gpt4o(api_key='<your-openai-api-key>'),\n my_image=image,\n)\nprint(desc)\n```\n*Output:*\n\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg\" width=\"520px\" alt=\"my_image\"></img>\n\n```\nImageDescription(\n items = [\n 0 : Item(\n name = 'Mercury',\n color = 'Gray'\n ),\n 1 : Item(\n name = 'Venus',\n color = 'Yellow'\n ),\n 2 : Item(\n name = 'Earth',\n color = 'Blue and white'\n ),\n 3 : Item(\n name = 'Moon',\n color = 'Gray'\n ),\n 4 : Item(\n name = 'Mars',\n color = 'Red'\n ),\n 5 : Item(\n name = 'Jupiter',\n color = 'Brown and white'\n ),\n 6 : Item(\n name = 'Saturn',\n color = 'Yellowish-brown with rings'\n ),\n 7 : Item(\n name = 'Uranus',\n color = 'Light blue'\n ),\n 8 : Item(\n name = 'Neptune',\n color = 'Dark blue'\n )\n ]\n)\n```\nSee [Langfun 101](https://colab.research.google.com/github/google/langfun/blob/main/docs/notebooks/langfun101.ipynb) for more examples.\n\n## Install\n\n```\npip install langfun\n```\n\nOr install nightly build with:\n\n```\npip install langfun --pre\n```\n\n\n\n*Disclaimer: this is not an officially supported Google product.*\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Langfun: Language as Functions.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/google/langfun"
},
"split_keywords": [
"llm",
"generative-ai",
"machine-learning"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "56f176da034b10daf56499150181a3c8ab33df19ac9e9defa867907b83f1a9d8",
"md5": "dedaa616c3c2e0f679bceadd099b53ee",
"sha256": "3ce79c14ee052ca9dc801e2a54f99b4b7212f8d38ad5df11228c226e4f2ed9de"
},
"downloads": -1,
"filename": "langfun-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dedaa616c3c2e0f679bceadd099b53ee",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 297453,
"upload_time": "2024-07-23T03:35:15",
"upload_time_iso_8601": "2024-07-23T03:35:15.962704Z",
"url": "https://files.pythonhosted.org/packages/56/f1/76da034b10daf56499150181a3c8ab33df19ac9e9defa867907b83f1a9d8/langfun-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e413887945729c5ef622949cb8ddc04c72d1534dcaed5aea4bf8f27638aa0b0c",
"md5": "81a1dd00c178b1d8c96175de0683278f",
"sha256": "413685ff6085f8bc9082f01e3f4b6c1522dcb958a94f798c8388d1d8384b3338"
},
"downloads": -1,
"filename": "langfun-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "81a1dd00c178b1d8c96175de0683278f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 207788,
"upload_time": "2024-07-23T03:35:18",
"upload_time_iso_8601": "2024-07-23T03:35:18.861792Z",
"url": "https://files.pythonhosted.org/packages/e4/13/887945729c5ef622949cb8ddc04c72d1534dcaed5aea4bf8f27638aa0b0c/langfun-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-23 03:35:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "google",
"github_project": "langfun",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "pyglove",
"specs": [
[
">=",
"0.4.5.dev202409110000"
]
]
},
{
"name": "jinja2",
"specs": [
[
">=",
"3.1.2"
]
]
},
{
"name": "requests",
"specs": [
[
">=",
"2.31.0"
]
]
},
{
"name": "termcolor",
"specs": [
[
"==",
"1.1.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.64.1"
]
]
},
{
"name": "google-auth",
"specs": [
[
">=",
"2.16.0"
]
]
},
{
"name": "python-magic",
"specs": [
[
">=",
"0.4.27"
]
]
},
{
"name": "python-docx",
"specs": [
[
">=",
"0.8.11"
]
]
},
{
"name": "pillow",
"specs": [
[
">=",
"10.0.0"
]
]
},
{
"name": "openpyxl",
"specs": [
[
">=",
"3.1.0"
]
]
},
{
"name": "pandas",
"specs": [
[
">=",
"2.0.3"
]
]
}
],
"lcname": "langfun"
}