From 5d7b1a4ee05ab4759a17c79c6a1727c1f1ce3dae Mon Sep 17 00:00:00 2001 From: Jason Liu Date: Mon, 17 Jul 2023 17:13:46 +0800 Subject: [PATCH] Better default descriptions (#62) * better desc * add better dsc test --- openai_function_call/function_calls.py | 6 ++++++ pyproject.toml | 2 +- tests/test_function_calls.py | 12 +++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/openai_function_call/function_calls.py b/openai_function_call/function_calls.py index b5bf95a..7d0b01e 100644 --- a/openai_function_call/function_calls.py +++ b/openai_function_call/function_calls.py @@ -133,6 +133,12 @@ class OpenAISchema(BaseModel): } parameters["required"] = sorted(parameters["properties"]) _remove_a_key(parameters, "title") + + if "description" not in schema: + schema[ + "description" + ] = f"Correctly extracted `{cls.__name__}` with all the required parameters with correct types" + return { "name": schema["title"], "description": schema["description"], diff --git a/pyproject.toml b/pyproject.toml index e10ed01..0bafedf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openai-function-call" -version = "0.1.1" +version = "0.1.2" description = "Helper functions that allow us to improve openai's function_call ergonomics" authors = ["Jason "] license = "MIT" diff --git a/tests/test_function_calls.py b/tests/test_function_calls.py index 57f0866..550f930 100644 --- a/tests/test_function_calls.py +++ b/tests/test_function_calls.py @@ -1,7 +1,7 @@ import pytest from pydantic import BaseModel -from openai_function_call import openai_schema +from openai_function_call import openai_schema, OpenAISchema def test_openai_schema(): @@ -30,3 +30,13 @@ def test_openai_schema_raises_error(): @openai_schema class Dummy: pass + + +def test_no_docstring(): + class Dummy(OpenAISchema): + attr: str + + assert ( + Dummy.openai_schema["description"] + == "Correctly extracted `Dummy` with all the required parameters with correct types" + )