langfun

OO for LLMs

https://github.com/google/langfun

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.0%) to scientific vocabulary

Keywords

framework llms nlp
Last synced: 4 months ago · JSON representation ·

Repository

OO for LLMs

Basic Info
  • Host: GitHub
  • Owner: google
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 1.8 MB
Statistics
  • Stars: 847
  • Watchers: 12
  • Forks: 63
  • Open Issues: 20
  • Releases: 3
Topics
framework llms nlp
Created over 2 years ago · Last pushed 4 months ago
Metadata Files
Readme Contributing License Citation

README.md

logo

Langfun

PyPI version codecov pytest

Installation | Getting started | Tutorial | Discord community

Introduction

Langfun is a 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. 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.fromuri('https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Solarsystem.jpg/1646px-Solar_system.jpg') display.display(image)

desc = lf.query( 'Describe objects in {{myimage}} from top to bottom.', ImageDescription, lm=lf.llms.Gpt4o(apikey=''), my_image=image, ) print(desc) ``` Output:

my_image

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 for more examples.

Install

Langfun offers a range of features through Extras, allowing users to install only what they need. The minimal installation of Langfun requires only PyGlove, Jinja2, and requests. To install Langfun with its minimal dependencies, use:

pip install langfun

For a complete installation with all dependencies, use:

pip install langfun[all]

To install a nightly build, include the --pre flag, like this:

pip install langfun[all] --pre

If you want to customize your installation, you can select specific features using package names like langfun[X1, X2, ..., Xn], where Xi corresponds to a tag from the list below:

| Tag | Description | | ------------------- | ---------------------------------------- | | all | All Langfun features. | | vertexai | VertexAI access. | | mime | All MIME supports. | | mime-pil | Image support for PIL. | | ui | UI enhancements |

For example, to install a nightly build that includes VertexAI access, full modality support, and UI enhancements, use:

pip install langfun[vertexai,mime,ui] --pre

Disclaimer: this is not an officially supported Google product.

Owner

  • Name: Google
  • Login: google
  • Kind: organization
  • Email: opensource@google.com
  • Location: United States of America

Google ❤️ Open Source

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: Langfun
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Daiyi
    family-names: Peng
    email: daiyip@outlook.com
    affiliation: Google Deepmind
repository-code: 'https://github.com/google/langfun'
license: Apache-2.0
version: 0.0.1
date-released: '2023-09-14'

Committers

Last synced: 4 months ago

All Time
  • Total Commits: 513
  • Total Committers: 12
  • Avg Commits per committer: 42.75
  • Development Distribution Score (DDS): 0.281
Past Year
  • Commits: 251
  • Committers: 10
  • Avg Commits per committer: 25.1
  • Development Distribution Score (DDS): 0.327
Top Committers
Name Email Commits
Daiyi Peng d****p@g****m 369
Yifeng Lu y****u@g****m 93
Langfun Authors n****y@g****m 27
D-X-Y d****y@a****m 9
Chengrun Yang c****n@g****m 4
Chu-Cheng Lin k****g@g****m 3
Jin Xu j****x@g****m 2
Amyssjj 1****j 2
Terry Koo t****o@g****m 1
Jiefeng Chen j****c@g****m 1
Da Huang d****a@g****m 1
Al Bo m****l 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 25
  • Total pull requests: 645
  • Average time to close issues: 23 days
  • Average time to close pull requests: 1 day
  • Total issue authors: 17
  • Total pull request authors: 8
  • Average comments per issue: 0.56
  • Average comments per pull request: 0.21
  • Merged pull requests: 452
  • Bot issues: 7
  • Bot pull requests: 631
Past Year
  • Issues: 21
  • Pull requests: 333
  • Average time to close issues: 10 days
  • Average time to close pull requests: about 11 hours
  • Issue authors: 14
  • Pull request authors: 6
  • Average comments per issue: 0.48
  • Average comments per pull request: 0.08
  • Merged pull requests: 254
  • Bot issues: 6
  • Bot pull requests: 322
Top Authors
Issue Authors
  • copybara-service[bot] (7)
  • Amyssjj (2)
  • jimgoo (2)
  • pseudotensor (1)
  • home3k (1)
  • verdverm (1)
  • tranhoangnguyen03 (1)
  • misteral (1)
  • timscodebase (1)
  • shantanuo (1)
  • rachittshah (1)
  • May0Mei (1)
  • Aaron617 (1)
  • Neko1313 (1)
  • arashbi (1)
Pull Request Authors
  • copybara-service[bot] (631)
  • Amyssjj (4)
  • misteral (2)
  • ghchinoy (2)
  • daiyip (2)
  • leo-gan (2)
  • jimgoo (1)
  • Ruijian-Zha (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 5,057 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 709
  • Total maintainers: 1
proxy.golang.org: github.com/google/langfun
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.4%
Average: 5.6%
Dependent repos count: 5.7%
Last synced: 4 months ago
pypi.org: langfun

Langfun: Language as Functions.

  • Versions: 706
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 5,057 Last month
Rankings
Dependent packages count: 7.4%
Downloads: 10.8%
Stargazers count: 17.7%
Forks count: 22.8%
Average: 25.5%
Dependent repos count: 68.9%
Maintainers (1)
Last synced: 4 months ago

Dependencies

.github/workflows/ci.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v1 composite
  • codecov/codecov-action v1 composite
.github/workflows/pypi-nightly.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v1 composite
.github/workflows/pypi.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v1 composite
requirements.txt pypi
  • jinja2 >=3.1.2
  • openai >=0.18.1
  • pyglove >=0.4.3
  • termcolor ==1.1.0
setup.py pypi