From 46180131a3194e06597de3316708205e08cb36b0 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 24 Aug 2023 00:28:06 -0700 Subject: [PATCH] formatting --- README.md | 20 ++++++++++++++++++- .../citation_with_extraction/modal_main.py | 4 +--- examples/patching/patching.py | 3 ++- .../query_planner_execution.py | 2 +- instructor/function_calls.py | 18 +++++++++++------ tests/test_function_calls.py | 16 +++++++-------- 6 files changed, 42 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index aade234..29ea3da 100644 --- a/README.md +++ b/README.md @@ -233,4 +233,22 @@ To see more examples of how we can create interesting models check out some [exa ## License -This project is licensed under the terms of the MIT License. \ No newline at end of file +This project is licensed under the terms of the MIT License. + + +$ openai_function_call git:(ft-cli) ✗ instructor jobs create-from-file data.jsonl + OpenAI Fine Tuning Job Monitoring +┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━┓ +┃ ┃ ┃ ┃ Completion ┃ ┃ ┃ ┃ ┃ +┃ Job ID ┃ Status ┃ Creation Time ┃ Time ┃ Model Name ┃ File ID ┃ Epochs ┃ Base Model ┃ +┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━┩ +│ ftjob-PWo6uwk… │ 🚫 cancelled │ 2023-08-23 │ N/A │ │ file-F7lJg6Z4… │ 3 │ gpt-3.5-turbo-… │ +│ │ │ 23:10:54 │ │ │ │ │ │ +│ ftjob-1whjva8… │ 🚫 cancelled │ 2023-08-23 │ N/A │ │ file-F7lJg6Z4… │ 3 │ gpt-3.5-turbo-… │ +│ │ │ 22:47:05 │ │ │ │ │ │ +│ ftjob-wGoBDld… │ 🚫 cancelled │ 2023-08-23 │ N/A │ │ file-F7lJg6Z4… │ 3 │ gpt-3.5-turbo-… │ +│ │ │ 22:44:12 │ │ │ │ │ │ +│ ftjob-yd5aRTc… │ ✅ succeeded │ 2023-08-23 │ 2023-08-23 │ ft:gpt-3.5-tur… │ file-IQxAUDqX… │ 3 │ gpt-3.5-turbo-… │ +│ │ │ 14:26:03 │ 15:02:29 │ │ │ │ │ +└────────────────┴──────────────┴────────────────┴────────────────┴─────────────────┴────────────────┴────────┴─────────────────┘ + Automatically refreshes every 5 seconds, press Ctrl+C to exit \ No newline at end of file diff --git a/examples/citation_with_extraction/modal_main.py b/examples/citation_with_extraction/modal_main.py index c8e61aa..5452486 100644 --- a/examples/citation_with_extraction/modal_main.py +++ b/examples/citation_with_extraction/modal_main.py @@ -3,9 +3,7 @@ import modal stub = modal.Stub("rag-citation") -image = modal.Image.debian_slim().pip_install( - "fastapi", "instructor>=0.2.1", "regex" -) +image = modal.Image.debian_slim().pip_install("fastapi", "instructor>=0.2.1", "regex") @stub.function(image=image) diff --git a/examples/patching/patching.py b/examples/patching/patching.py index 4aafdde..180bcb5 100644 --- a/examples/patching/patching.py +++ b/examples/patching/patching.py @@ -12,6 +12,7 @@ class UserExtract(BaseModel): name: str age: int + user: UserExtract = openai.ChatCompletion.create( model="gpt-3.5-turbo", response_model=UserExtract, @@ -20,4 +21,4 @@ user: UserExtract = openai.ChatCompletion.create( ], ) # type: ignore -print(user) \ No newline at end of file +print(user) diff --git a/examples/query_planner_execution/query_planner_execution.py b/examples/query_planner_execution/query_planner_execution.py index b2c3d1a..a937f6d 100644 --- a/examples/query_planner_execution/query_planner_execution.py +++ b/examples/query_planner_execution/query_planner_execution.py @@ -138,7 +138,7 @@ def query_planner(question: str, plan=False) -> QueryPlan: max_tokens=1000, ) - messages.append(completion['choices'][0]['message']) + messages.append(completion["choices"][0]["message"]) messages.append( { diff --git a/instructor/function_calls.py b/instructor/function_calls.py index edc5120..3043a0a 100644 --- a/instructor/function_calls.py +++ b/instructor/function_calls.py @@ -75,7 +75,9 @@ class openai_function: if k not in ("v__duplicate_kwargs", "args", "kwargs") } for param in self.docstring.params: - if (name := param.arg_name) in parameters["properties"] and (description := param.description): + if (name := param.arg_name) in parameters["properties"] and ( + description := param.description + ): parameters["properties"][name]["description"] = description parameters["required"] = sorted( k for k, v in parameters["properties"].items() if not "default" in v @@ -107,7 +109,7 @@ class openai_function: Returns: result (any): result of the function call """ - message = completion['choices'][0]['message'] + message = completion["choices"][0]["message"] if throw_error: assert "function_call" in message, "No function call detected" @@ -139,7 +141,9 @@ class OpenAISchema(BaseModel): k: v for k, v in schema.items() if k not in ("title", "description") } for param in docstring.params: - if (name := param.arg_name) in parameters["properties"] and (description := param.description): + if (name := param.arg_name) in parameters["properties"] and ( + description := param.description + ): if "description" not in parameters["properties"][name]: parameters["properties"][name]["description"] = description @@ -151,8 +155,10 @@ class OpenAISchema(BaseModel): if docstring.short_description: schema["description"] = docstring.short_description else: - schema["description"] = f"Correctly extracted `{cls.__name__}` with all " \ - f"the required parameters with correct types" + schema["description"] = ( + f"Correctly extracted `{cls.__name__}` with all " + f"the required parameters with correct types" + ) _remove_a_key(parameters, "additionalProperties") _remove_a_key(parameters, "title") @@ -173,7 +179,7 @@ class OpenAISchema(BaseModel): Returns: cls (OpenAISchema): An instance of the class """ - message = completion['choices'][0]['message'] + message = completion["choices"][0]["message"] if throw_error: assert "function_call" in message, "No function call detected" diff --git a/tests/test_function_calls.py b/tests/test_function_calls.py index bc4c957..4698685 100644 --- a/tests/test_function_calls.py +++ b/tests/test_function_calls.py @@ -47,7 +47,7 @@ def test_no_docstring(): def test_openai_function(): @openai_function def get_current_weather( - location: str, format: Literal["celsius", "fahrenheit"] = "celsius" + location: str, format: Literal["celsius", "fahrenheit"] = "celsius" ): """ Gets the current weather in a given location, use this function for any questions related to the weather @@ -63,7 +63,7 @@ def test_openai_function(): @openai_function def get_current_weather_no_format_docstring( - location: str, format: Literal["celsius", "fahrenheit"] = "celsius" + location: str, format: Literal["celsius", "fahrenheit"] = "celsius" ): """ Gets the current weather in a given location, use this function for any questions related to the weather @@ -77,13 +77,11 @@ def test_openai_function(): scheme_missing_param = get_current_weather_no_format_docstring.openai_schema assert ( scheme_missing_param["parameters"]["properties"]["location"]["description"] - == - "The city to get the weather, e.g. San Francisco. Guess the location from user messages" - ) - assert ( - scheme_missing_param["parameters"]["properties"]["format"]["enum"] - == - ["celsius", "fahrenheit"] + == "The city to get the weather, e.g. San Francisco. Guess the location from user messages" ) + assert scheme_missing_param["parameters"]["properties"]["format"]["enum"] == [ + "celsius", + "fahrenheit", + ] with pytest.raises(KeyError, match="description"): scheme_missing_param["parameters"]["properties"]["format"]["description"]