{"id":17665324,"url":"https://github.com/google/langfun","last_synced_at":"2026-04-10T10:02:57.130Z","repository":{"id":194726302,"uuid":"684718744","full_name":"google/langfun","owner":"google","description":"OO for LLMs","archived":false,"fork":false,"pushed_at":"2025-01-07T05:24:29.000Z","size":1265,"stargazers_count":587,"open_issues_count":8,"forks_count":42,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-01-07T16:08:23.526Z","etag":null,"topics":["framework","llms","nlp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-29T17:58:47.000Z","updated_at":"2025-01-07T00:03:32.000Z","dependencies_parsed_at":"2023-12-16T01:44:58.575Z","dependency_job_id":"1b618cf6-feea-4a7d-a530-c033373aed3a","html_url":"https://github.com/google/langfun","commit_stats":null,"previous_names":["google/langfun"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flangfun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flangfun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flangfun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Flangfun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/langfun/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243059820,"owners_count":20229642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","llms","nlp"],"created_at":"2024-10-23T21:01:17.061Z","updated_at":"2026-04-10T10:02:57.116Z","avatar_url":"https://github.com/google.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg\" width=\"520px\" alt=\"logo\"\u003e\u003c/img\u003e\n\u003c/div\u003e\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) | [**Discord community**](https://discord.gg/U6wPN9R68k)\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='\u003cyour-openai-api-key\u003e'),\n    my_image=image,\n)\nprint(desc)\n```\n*Output:*\n\n\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solar_system.jpg/1646px-Solar_system.jpg\" width=\"520px\" alt=\"my_image\"\u003e\u003c/img\u003e\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\nLangfun offers a range of features through [Extras](https://packaging.python.org/en/latest/tutorials/installing-packages/#installing-extras), allowing users to install only what they need. The minimal installation of Langfun requires only [PyGlove](https://github.com/google/pyglove), [Jinja2](https://github.com/pallets/jinja/), and [requests](https://github.com/psf/requests). To install Langfun with its minimal dependencies, use:\n\n```\npip install langfun\n```\n\nFor a complete installation with all dependencies, use:\n\n```\npip install langfun[all]\n```\n\nTo install a nightly build, include the `--pre` flag, like this:\n\n```\npip install langfun[all] --pre\n```\n\nIf you want to customize your installation, you can select specific features\nusing package names like `langfun[X1, X2, ..., Xn]`, where `Xi` corresponds to\na tag from the list below:\n\n| Tag                 |  Description                             |\n| ------------------- | ---------------------------------------- |\n| all                 | All Langfun features.                    |\n| vertexai            | VertexAI access.                         |\n| mime                | All MIME supports.                       |\n| mime-pil            | Image support for PIL.                   |\n| ui                  | UI enhancements                          |\n\nFor example, to install a nightly build that includes VertexAI access, full\nmodality support, and UI enhancements, use:\n\n```\npip install langfun[vertexai,mime,ui] --pre\n```\n\n*Disclaimer: this is not an officially supported Google product.*\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Flangfun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Flangfun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Flangfun/lists"}