langfun


Namelangfun JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://github.com/google/langfun
SummaryLangfun: Language as Functions.
upload_time2023-09-14 21:44:06
maintainer
docs_urlNone
authorLangfun Authors
requires_python
licenseApache License 2.0
keywords llm generative-ai machine-learning
VCS
bugtrack_url
requirements google-cloud-aiplatform google-generativeai jinja2 openai pyglove python-magic requests termcolor tqdm
Travis-CI No Travis.
coveralls test coverage
            <div align="center">
<img src="https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg#gh-light-mode-only" width="320px" alt="logo"></img>

</div>

# Langfun

Langfun is a Python library that aims to make language models (LM) fun
to work with. Its design enables a programming model that flows naturally,
resembling the human thought process. It emphasizes the reuse and combination of
language pieces to form prompts, thereby accelerating innovation. In contrast to
other LM frameworks, which feed program-generated data into the LM, langfun
takes a distinct approach: It starts with natural language, allowing for
seamless interactions between language and program logic, and concludes with
natural language and optional structured output. Consequently, langfun can
aptly be described as Language as functions, capturing the core of its
methodology.

## Install

```
pip install langfun
```

Or install nightly build with:

```
pip install langfun --pre
```

## Hello World

```python
import langfun as lf

class NumericAnswerExtractor(lf.LangFunc):
  """Numeric answer extractor.

  Here is my question:
  {{question}}

  Here is the response:
  {{question()}}

  Can you help me extract a number from the response as the answer to my
  question? Your response should only contain a number in numeric form.
  If the answer is not a number or you cannot extract it, respond with UNKNOWN.
  """
  output_transform = lf.transforms.Match('\d+').to_int()

l = NumericAnswerExtractor()

with lf.context(lm=lf.llms.Gpt35(debug=True)):
  r = l(question=lf.LangFunc('What is result of {{x}} plus {{y}}?'),
        x='one',
        y='two')
  print('Result:', r.result)
```

*Disclaimer: this is not an officially supported Google product.*

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/google/langfun",
    "name": "langfun",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "llm generative-ai machine-learning",
    "author": "Langfun Authors",
    "author_email": "langfun-authors@google.com",
    "download_url": "https://files.pythonhosted.org/packages/b6/6f/e3d549689fb94fc677ed65ad3dc5df3f2ec54eccfe6bdeb361cd7b27ce09/langfun-0.0.1.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n<img src=\"https://raw.githubusercontent.com/google/langfun/main/docs/_static/logo.svg#gh-light-mode-only\" width=\"320px\" alt=\"logo\"></img>\n\n</div>\n\n# Langfun\n\nLangfun is a Python library that aims to make language models (LM) fun\nto work with. Its design enables a programming model that flows naturally,\nresembling the human thought process. It emphasizes the reuse and combination of\nlanguage pieces to form prompts, thereby accelerating innovation. In contrast to\nother LM frameworks, which feed program-generated data into the LM, langfun\ntakes a distinct approach: It starts with natural language, allowing for\nseamless interactions between language and program logic, and concludes with\nnatural language and optional structured output. Consequently, langfun can\naptly be described as Language as functions, capturing the core of its\nmethodology.\n\n## Install\n\n```\npip install langfun\n```\n\nOr install nightly build with:\n\n```\npip install langfun --pre\n```\n\n## Hello World\n\n```python\nimport langfun as lf\n\nclass NumericAnswerExtractor(lf.LangFunc):\n  \"\"\"Numeric answer extractor.\n\n  Here is my question:\n  {{question}}\n\n  Here is the response:\n  {{question()}}\n\n  Can you help me extract a number from the response as the answer to my\n  question? Your response should only contain a number in numeric form.\n  If the answer is not a number or you cannot extract it, respond with UNKNOWN.\n  \"\"\"\n  output_transform = lf.transforms.Match('\\d+').to_int()\n\nl = NumericAnswerExtractor()\n\nwith lf.context(lm=lf.llms.Gpt35(debug=True)):\n  r = l(question=lf.LangFunc('What is result of {{x}} plus {{y}}?'),\n        x='one',\n        y='two')\n  print('Result:', r.result)\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.0.1",
    "project_urls": {
        "Homepage": "https://github.com/google/langfun"
    },
    "split_keywords": [
        "llm",
        "generative-ai",
        "machine-learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e9de4c14be448d76c7a07a5982a875c42109fb0c144ddee8c2f458fc311b46f",
                "md5": "49a59cf9f1a6ce89b6ffac3053c1b340",
                "sha256": "1f35c51a48f104c2501217dafd43e770e559f96adc6b7ecfa930ee1a5330cf34"
            },
            "downloads": -1,
            "filename": "langfun-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "49a59cf9f1a6ce89b6ffac3053c1b340",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 116205,
            "upload_time": "2023-09-14T21:44:04",
            "upload_time_iso_8601": "2023-09-14T21:44:04.634620Z",
            "url": "https://files.pythonhosted.org/packages/5e/9d/e4c14be448d76c7a07a5982a875c42109fb0c144ddee8c2f458fc311b46f/langfun-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b66fe3d549689fb94fc677ed65ad3dc5df3f2ec54eccfe6bdeb361cd7b27ce09",
                "md5": "921f25c78daed3dd8d2378b0b433f748",
                "sha256": "ad2e05a0927cc4b2ae85a044b54cb4a7e2701d84685e99a66ee945f0380edb14"
            },
            "downloads": -1,
            "filename": "langfun-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "921f25c78daed3dd8d2378b0b433f748",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 80499,
            "upload_time": "2023-09-14T21:44:06",
            "upload_time_iso_8601": "2023-09-14T21:44:06.701318Z",
            "url": "https://files.pythonhosted.org/packages/b6/6f/e3d549689fb94fc677ed65ad3dc5df3f2ec54eccfe6bdeb361cd7b27ce09/langfun-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 21:44:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "google",
    "github_project": "langfun",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "google-cloud-aiplatform",
            "specs": [
                [
                    ">=",
                    "1.5.0"
                ]
            ]
        },
        {
            "name": "google-generativeai",
            "specs": [
                [
                    ">=",
                    "0.3.2"
                ]
            ]
        },
        {
            "name": "jinja2",
            "specs": [
                [
                    ">=",
                    "3.1.2"
                ]
            ]
        },
        {
            "name": "openai",
            "specs": [
                [
                    "==",
                    "0.27.2"
                ]
            ]
        },
        {
            "name": "pyglove",
            "specs": [
                [
                    ">=",
                    "0.4.5.dev20240423"
                ]
            ]
        },
        {
            "name": "python-magic",
            "specs": [
                [
                    ">=",
                    "0.4.27"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "termcolor",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": [
                [
                    ">=",
                    "4.64.1"
                ]
            ]
        }
    ],
    "lcname": "langfun"
}
        
Elapsed time: 0.26382s