{"id":13584819,"url":"https://github.com/rizerphe/local-llm-function-calling","last_synced_at":"2025-10-26T09:12:19.749Z","repository":{"id":176641039,"uuid":"659211539","full_name":"rizerphe/local-llm-function-calling","owner":"rizerphe","description":"A tool for generating function arguments and choosing what function to call with local LLMs","archived":false,"fork":false,"pushed_at":"2024-03-12T12:29:36.000Z","size":167,"stargazers_count":422,"open_issues_count":5,"forks_count":41,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-28T07:09:13.592Z","etag":null,"topics":["chatgpt-functions","huggingface-transformers","json-schema","llm","llm-inference","openai-function-call","openai-functions"],"latest_commit_sha":null,"homepage":"https://local-llm-function-calling.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rizerphe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-06-27T11:02:41.000Z","updated_at":"2025-03-27T02:13:18.000Z","dependencies_parsed_at":"2024-04-11T21:12:41.988Z","dependency_job_id":"af8da741-d42c-46ca-9c49-7f9a23b843d8","html_url":"https://github.com/rizerphe/local-llm-function-calling","commit_stats":null,"previous_names":["rizerphe/local-llm-function-calling"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Flocal-llm-function-calling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Flocal-llm-function-calling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Flocal-llm-function-calling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Flocal-llm-function-calling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rizerphe","download_url":"https://codeload.github.com/rizerphe/local-llm-function-calling/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142063,"owners_count":20890652,"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":["chatgpt-functions","huggingface-transformers","json-schema","llm","llm-inference","openai-function-call","openai-functions"],"created_at":"2024-08-01T15:04:32.422Z","updated_at":"2025-10-26T09:12:14.694Z","avatar_url":"https://github.com/rizerphe.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Local LLM function calling\n\n[![Documentation Status](https://readthedocs.org/projects/local-llm-function-calling/badge/?version=latest)](https://local-llm-function-calling.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/local-llm-function-calling.svg)](https://badge.fury.io/py/local-llm-function-calling)\n\n## Overview\n\nThe `local-llm-function-calling` project is designed to constrain the generation of Hugging Face text generation models by enforcing a JSON schema and facilitating the formulation of prompts for function calls, similar to OpenAI's [function calling](https://openai.com/blog/function-calling-and-other-api-updates) feature, but actually enforcing the schema unlike OpenAI.\n\nThe project provides a `Generator` class that allows users to easily generate text while ensuring compliance with the provided prompt and JSON schema. By utilizing the `local-llm-function-calling` library, users can conveniently control the output of text generation models. It uses my own quickly sketched `json-schema-enforcer` project as the enforcer.\n\n## Features\n\n- Constrains the generation of Hugging Face text generation models to follow a JSON schema.\n- Provides a mechanism for formulating prompts for function calls, enabling precise data extraction and formatting.\n- Simplifies the text generation process through a user-friendly `Generator` class.\n\n## Installation\n\nTo install the `local-llm-function-calling` library, use the following command:\n\n```shell\npip install local-llm-function-calling\n```\n\n## Usage\n\nHere's a simple example demonstrating how to use `local-llm-function-calling`:\n\n```python\nfrom local_llm_function_calling import Generator\n\n# Define a function and models\nfunctions = [\n    {\n        \"name\": \"get_current_weather\",\n        \"description\": \"Get the current weather in a given location\",\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"location\": {\n                    \"type\": \"string\",\n                    \"description\": \"The city and state, e.g. San Francisco, CA\",\n                    \"maxLength\": 20,\n                },\n                \"unit\": {\"type\": \"string\", \"enum\": [\"celsius\", \"fahrenheit\"]},\n            },\n            \"required\": [\"location\"],\n        },\n    }\n]\n\n# Initialize the generator with the Hugging Face model and our functions\ngenerator = Generator.hf(functions, \"gpt2\")\n\n# Generate text using a prompt\nfunction_call = generator.generate(\"What is the weather like today in Brooklyn?\")\nprint(function_call)\n```\n\n## Custom constraints\n\nYou don't have to use my prompting methods; you can craft your own prompts and your own constraints, and still benefit from the constrained generation:\n\n```python\nfrom local_llm_function_calling import Constrainer\nfrom local_llm_function_calling.model.huggingface import HuggingfaceModel\n\n# Define your own constraint\n# (you can also use local_llm_function_calling.JsonSchemaConstraint)\ndef lowercase_sentence_constraint(text: str):\n    # Has to return (is_valid, is_complete)\n    return [text.islower(), text.endswith(\".\")]\n\n# Create the constrainer\nconstrainer = Constrainer(HuggingfaceModel(\"gpt2\"))\n\n# Generate your text\ngenerated = constrainer.generate(\"Prefix.\\n\", lowercase_sentence_constraint, max_len=10)\n```\n\n## Extending and Customizing\n\nTo extend or customize the prompt structure, you can subclass the `TextPrompter` class. This allows you to modify the prompt generation process according to your specific requirements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizerphe%2Flocal-llm-function-calling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frizerphe%2Flocal-llm-function-calling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizerphe%2Flocal-llm-function-calling/lists"}