-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(openai-callback): add Azure OpenAI fine-tuned models #694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,105 @@ def test_handler_unknown_model(self, handler: OpenAICallbackHandler) -> None: | |
# cost must be 0.0 for unknown model | ||
assert handler.total_cost == 0.0 | ||
|
||
@pytest.mark.skip | ||
@pytest.mark.parametrize( | ||
"model_name,expected_cost", | ||
[ | ||
("gpt-3.5-turbo", 0.0035), | ||
( | ||
"gpt-3.5-turbo-0613", | ||
0.0035, | ||
), | ||
( | ||
"gpt-3.5-turbo-16k-0613", | ||
0.007, | ||
), | ||
( | ||
"gpt-3.5-turbo-16k", | ||
0.007, | ||
), | ||
("gpt-4", 0.09), | ||
("gpt-4-0613", 0.09), | ||
("gpt-4-32k", 0.18), | ||
("gpt-4-32k-0613", 0.18), | ||
], | ||
) | ||
def test_handler_openai( | ||
self, handler: OpenAICallbackHandler, model_name: str, expected_cost: float | ||
) -> None: | ||
response = OpenAIObject.construct_from( | ||
{ | ||
"usage": { | ||
"prompt_tokens": 1000, | ||
"completion_tokens": 1000, | ||
"total_tokens": 2000, | ||
}, | ||
"model": model_name, | ||
} | ||
) | ||
handler(response) | ||
assert handler.total_cost == expected_cost | ||
|
||
@pytest.mark.parametrize( | ||
"model_name,expected_cost", | ||
[ | ||
("gpt-35-turbo", 0.0035), | ||
( | ||
"gpt-35-turbo-0613", | ||
0.0035, | ||
), | ||
( | ||
"gpt-35-turbo-16k-0613", | ||
0.007, | ||
), | ||
( | ||
"gpt-35-turbo-16k", | ||
0.007, | ||
), | ||
("gpt-4", 0.09), | ||
("gpt-4-0613", 0.09), | ||
("gpt-4-32k", 0.18), | ||
("gpt-4-32k-0613", 0.18), | ||
], | ||
) | ||
Comment on lines
+98
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
def test_handler_azure_openai( | ||
self, handler: OpenAICallbackHandler, model_name: str, expected_cost: float | ||
) -> None: | ||
response = OpenAIObject.construct_from( | ||
{ | ||
"usage": { | ||
"prompt_tokens": 1000, | ||
"completion_tokens": 1000, | ||
"total_tokens": 2000, | ||
}, | ||
"model": model_name, | ||
} | ||
) | ||
handler(response) | ||
assert handler.total_cost == expected_cost | ||
|
||
@pytest.mark.parametrize( | ||
"model_name, expected_cost", | ||
[ | ||
("ft:gpt-3.5-turbo-0613:your-org:custom-model-name:1abcdefg", 0.028), | ||
("gpt-35-turbo-0613.ft-0123456789abcdefghijklmnopqrstuv", 0.0035), | ||
], | ||
) | ||
def test_handler_finetuned_model( | ||
self, handler: OpenAICallbackHandler, model_name: str, expected_cost: float | ||
): | ||
response = OpenAIObject.construct_from( | ||
{ | ||
"usage": { | ||
"prompt_tokens": 1000, | ||
"completion_tokens": 1000, | ||
"total_tokens": 2000, | ||
}, | ||
"model": model_name, | ||
} | ||
) | ||
handler(response) | ||
assert handler.total_cost == expected_cost | ||
|
||
def test_openai_callback(self, mocker): | ||
df = pd.DataFrame([1, 2, 3]) | ||
llm = OpenAI(api_token="test") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
standardize_model_name()
function is a good addition to the codebase. It improves code consistency and readability by standardizing the model name for use in the OpenAI API. However, the function could be simplified by using a dictionary to map the model prefixes to their standardized names, which would make the code more maintainable and easier to extend in the future.