{"id":20466035,"url":"https://github.com/rizerphe/openai-functions","last_synced_at":"2025-04-13T08:55:16.624Z","repository":{"id":176391324,"uuid":"657209972","full_name":"rizerphe/openai-functions","owner":"rizerphe","description":"Generate ChatGPT function call schemas based on function docstrings.","archived":false,"fork":false,"pushed_at":"2023-09-29T15:27:46.000Z","size":183,"stargazers_count":57,"open_issues_count":3,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T00:33:56.825Z","etag":null,"topics":["chatgpt","chatgpt-api","chatgpt-functions","nlp","openai","openai-api","openai-chatgpt","openai-function-call","openai-functions","python","python-library"],"latest_commit_sha":null,"homepage":"https://openai-functions.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,"publiccode":null,"codemeta":null}},"created_at":"2023-06-22T14:54:33.000Z","updated_at":"2025-01-16T17:59:31.000Z","dependencies_parsed_at":"2024-11-15T13:32:28.585Z","dependency_job_id":null,"html_url":"https://github.com/rizerphe/openai-functions","commit_stats":null,"previous_names":["rizerphe/openai-functions"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fopenai-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fopenai-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fopenai-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizerphe%2Fopenai-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rizerphe","download_url":"https://codeload.github.com/rizerphe/openai-functions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248688544,"owners_count":21145763,"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","chatgpt-api","chatgpt-functions","nlp","openai","openai-api","openai-chatgpt","openai-function-call","openai-functions","python","python-library"],"created_at":"2024-11-15T13:21:14.154Z","updated_at":"2025-04-13T08:55:16.617Z","avatar_url":"https://github.com/rizerphe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenAI functions\n\nThe `openai-functions` Python project simplifies the usage of OpenAI's ChatGPT [function calling](https://platform.openai.com/docs/guides/gpt/function-calling) feature. It abstracts away the complexity of parsing function signatures and docstrings by providing developers with a clean and intuitive interface.\n\n![Tests](https://github.com/rizerphe/openai-functions/actions/workflows/tests.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/rizerphe/openai-functions/badge.svg?branch=main)](https://coveralls.io/github/rizerphe/openai-functions?branch=main) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PyPI version](https://badge.fury.io/py/openai-functions.svg)](https://badge.fury.io/py/openai-functions) [![Documentation Status](https://readthedocs.org/projects/openai-functions/badge/?version=latest)](https://openai-functions.readthedocs.io/en/latest/?badge=latest)\n\n## Installation\n\nYou can install `openai-functions` from PyPI using pip:\n\n```\npip install openai-functions\n```\n\n## Usage\n\n1. Import the necessary modules and provide your API key:\n\n```python\nimport enum\nimport openai\nfrom openai_functions import Conversation\n\nopenai.api_key = \"\u003cYOUR_API_KEY\u003e\"\n```\n\n2. Create a `Conversation` instance:\n\n```python\nconversation = Conversation()\n```\n\n3. Define your functions using the `@conversation.add_function` decorator:\n\n```python\nclass Unit(enum.Enum):\n    FAHRENHEIT = \"fahrenheit\"\n    CELSIUS = \"celsius\"\n\n@conversation.add_function()\ndef get_current_weather(location: str, unit: Unit = Unit.FAHRENHEIT) -\u003e dict:\n    \"\"\"Get the current weather in a given location.\n\n    Args:\n        location (str): The city and state, e.g., San Francisco, CA\n        unit (Unit): The unit to use, e.g., fahrenheit or celsius\n    \"\"\"\n    return {\n        \"location\": location,\n        \"temperature\": \"72\",\n        \"unit\": unit.value,\n        \"forecast\": [\"sunny\", \"windy\"],\n    }\n```\n\n4. Ask the AI a question:\n\n```python\nresponse = conversation.ask(\"What's the weather in San Francisco?\")\n# Should return something like:\n# The current weather in San Francisco is 72 degrees Fahrenheit and it is sunny and windy.\n```\n\nYou can read more about how to use `Conversation` [here](https://openai-functions.readthedocs.io/en/latest/conversation.html).\n\n## More barebones use - just schema generation and result parsing:\n\n```python\nfrom openai_functions import FunctionWrapper\n\nwrapper = FunctionWrapper(get_current_weather)\nschema = wrapper.schema\nresult = wrapper({\"location\": \"San Francisco, CA\"})\n```\n\nOr you could use [skills](https://openai-functions.readthedocs.io/en/latest/skills.html).\n\n## Another use case: data extraction\n\n1. Import the necessary modules and provide your API key:\n\n```python\nfrom dataclasses import dataclass\nimport openai\nfrom openai_functions import nlp\n\nopenai.api_key = \"\u003cYOUR_API_KEY\u003e\"\n```\n\n3. Define your data container using the `@nlp` decorator:\n\n```python\n@nlp\n@dataclass\nclass Person:\n    \"\"\"Extract personal info\"\"\"\n\n    name: str\n    age: int\n```\n\n4. Ask the AI for the extracted data:\n\n```python\nperson = Person.from_natural_language(\"I'm Jack and I'm 20 years old.\")\n```\n\nYou can read more about `@nlp` [here](https://openai-functions.readthedocs.io/en/latest/nlp_interface.html).\n\nNote: mypy does not parse class decorators ([#3135](https://github.com/python/mypy/issues/3135)), so you might have trouble getting type checking when using it like this. Consider using something like `nlp(Person).from_natural_language` to get proper type support.\n\n## How it Works\n\n`openai-functions` takes care of the following tasks:\n\n- Parsing the function signatures (with type annotations) and docstrings.\n- Sending the conversation and function descriptions to the OpenAI model.\n- Deciding whether to call a function based on the model's response.\n- Calling the appropriate function with the provided arguments.\n- Updating the conversation with the function response.\n- Repeating the process until the model generates a user-facing message.\n\nThis abstraction allows developers to focus on defining their functions and adding user messages without worrying about the details of function calling.\n\n## Note\n\nPlease note that `openai-functions` is an unofficial project not maintained by OpenAI. Use it at your discretion.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizerphe%2Fopenai-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frizerphe%2Fopenai-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizerphe%2Fopenai-functions/lists"}