Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl committed Aug 24, 2023
1 parent 3ca4f9b commit 4618013
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
4 changes: 1 addition & 3 deletions examples/citation_with_extraction/modal_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

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)
Expand Down
3 changes: 2 additions & 1 deletion examples/patching/patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class UserExtract(BaseModel):
name: str
age: int


user: UserExtract = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
response_model=UserExtract,
Expand All @@ -20,4 +21,4 @@ class UserExtract(BaseModel):
],
) # type: ignore

print(user)
print(user)
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
18 changes: 12 additions & 6 deletions instructor/function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def __init__(self, func: Callable) -> None:
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
Expand Down Expand Up @@ -107,7 +109,7 @@ def from_response(self, completion, throw_error=True):
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"
Expand Down Expand Up @@ -139,7 +141,9 @@ def openai_schema(cls):
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

Expand All @@ -151,8 +155,10 @@ def openai_schema(cls):
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")
Expand All @@ -173,7 +179,7 @@ def from_response(cls, completion, throw_error=True):
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"
Expand Down
16 changes: 7 additions & 9 deletions tests/test_function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Dummy(OpenAISchema):
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
Expand All @@ -63,7 +63,7 @@ def get_current_weather(

@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
Expand All @@ -77,13 +77,11 @@ def get_current_weather_no_format_docstring(
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"]

0 comments on commit 4618013

Please sign in to comment.