-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track chatbot activity in posthog (#1923)
- Loading branch information
Showing
2 changed files
with
33 additions
and
5 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
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 |
---|---|---|
|
@@ -233,12 +233,13 @@ def test_get_completion(mocker): | |
"system_prompt": SearchAgent.INSTRUCTIONS, | ||
} | ||
} | ||
expected_return_value = [b"Here ", b"are ", b"some ", b"results"] | ||
expected_return_value = ["Here ", "are ", "some ", "results"] | ||
mocker.patch( | ||
"ai_chat.agents.OpenAIAgent.stream_chat", | ||
return_value=mocker.Mock(response_gen=iter(expected_return_value)), | ||
) | ||
search_agent = SearchAgent("test agent") | ||
mock_hog = mocker.patch("ai_chat.agents.posthog.Posthog") | ||
search_agent = SearchAgent("test agent", user_id="[email protected]") | ||
search_agent.search_parameters = metadata["metadata"]["search_parameters"] | ||
search_agent.search_results = metadata["metadata"]["search_results"] | ||
search_agent.instructions = metadata["metadata"]["system_prompt"] | ||
|
@@ -256,4 +257,14 @@ def test_get_completion(mocker): | |
] | ||
) | ||
search_agent.agent.stream_chat.assert_called_once_with("I want to learn physics") | ||
mock_hog.return_value.capture.assert_called_once_with( | ||
"[email protected]", | ||
event=search_agent.JOB_ID, | ||
properties={ | ||
"question": "I want to learn physics", | ||
"answer": "Here are some results", | ||
"metadata": search_agent.get_comment_metadata(), | ||
"user": "[email protected]", | ||
}, | ||
) | ||
assert "".join([str(value) for value in expected_return_value]) in results |