-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Completions.mock_chat_completions to insert logs into Log10 (#328)
* add Completions.mock_chat_completions to insert logs into Log10 * add test for mock_chat_completions and minor edits * add a test case for model=claude
1 parent
50759a9
commit 8051efe
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from log10.completions import Completions | ||
from log10.load import log10_tags | ||
|
||
|
||
def main(): | ||
completions = Completions() | ||
model = "gpt-4o" | ||
messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "What's the capital of France?"}, | ||
] | ||
response_content = "The capital of France is Paris." | ||
with log10_tags(["examples"]): | ||
result = completions.mock_chat_completions( | ||
model=model, messages=messages, response_content=response_content, tags=["geography"] | ||
) | ||
print(f"Assistant's response: {result.choices[0].message.content}") | ||
print(f"Model used: {result.model}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .completions import Completions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
from log10.completions import Completions | ||
from tests.utils import _LogAssertion | ||
|
||
|
||
@pytest.mark.chat | ||
@pytest.mark.parametrize("model", ["claude-3-haiku-20240307", "gpt-4o"]) | ||
def test_mock_chat_completions(model): | ||
cmpl = Completions() | ||
|
||
messages = [ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": "What's the capital of France?"}, | ||
] | ||
response_content = "The capital of France is Paris." | ||
tags = ["pytest", "geography"] | ||
|
||
result = cmpl.mock_chat_completions(model=model, messages=messages, response_content=response_content, tags=tags) | ||
|
||
assert result.model == model | ||
assert result.choices[0].message.content == response_content | ||
assert result.choices[0].message.role == "assistant" | ||
assert result.object == "chat.completion" | ||
|
||
_LogAssertion( | ||
completion_id=result.id.replace("chatcmpl-", ""), message_content=response_content | ||
).assert_chat_response() |