1313# limitations under the License.
1414from __future__ import annotations
1515
16- import sys
17- from typing import Generator
1816from unittest .mock import AsyncMock , MagicMock , Mock , patch
1917
20- import anthropic
2118import pytest
2219from neo4j_graphrag .exceptions import LLMGenerationError
2320from neo4j_graphrag .llm .anthropic_llm import AnthropicLLM
@@ -54,17 +51,21 @@ def test_anthropic_invoke_with_chat_history_happy_path(mock_anthropic: Mock) ->
5451 )
5552 model_params = {"temperature" : 0.3 }
5653 system_instruction = "You are a helpful assistant."
57- llm = AnthropicLLM ("claude-3-opus-20240229" , model_params = model_params , system_instruction = system_instruction )
54+ llm = AnthropicLLM (
55+ "claude-3-opus-20240229" ,
56+ model_params = model_params ,
57+ system_instruction = system_instruction ,
58+ )
5859 chat_history = [
5960 {"role" : "user" , "content" : "When does the sun come up in the summer?" },
6061 {"role" : "assistant" , "content" : "Usually around 6am." },
6162 ]
6263 question = "What about next season?"
63-
64+
6465 response = llm .invoke (question , chat_history )
6566 assert response .content == "generated text"
6667 chat_history .append ({"role" : "user" , "content" : question })
67- llm .client .messages .create .assert_called_once_with ( # type: ignore
68+ llm .client .messages .create .assert_called_once_with (
6869 messages = chat_history ,
6970 model = "claude-3-opus-20240229" ,
7071 system = system_instruction ,
@@ -73,13 +74,19 @@ def test_anthropic_invoke_with_chat_history_happy_path(mock_anthropic: Mock) ->
7374
7475
7576@patch ("neo4j_graphrag.llm.anthropic_llm.anthropic.Anthropic" )
76- def test_anthropic_invoke_with_chat_history_validation_error (mock_anthropic : Mock ) -> None :
77+ def test_anthropic_invoke_with_chat_history_validation_error (
78+ mock_anthropic : Mock ,
79+ ) -> None :
7780 mock_anthropic .return_value .messages .create .return_value = MagicMock (
7881 content = "generated text"
7982 )
8083 model_params = {"temperature" : 0.3 }
8184 system_instruction = "You are a helpful assistant."
82- llm = AnthropicLLM ("claude-3-opus-20240229" , model_params = model_params , system_instruction = system_instruction )
85+ llm = AnthropicLLM (
86+ "claude-3-opus-20240229" ,
87+ model_params = model_params ,
88+ system_instruction = system_instruction ,
89+ )
8390 chat_history = [
8491 {"role" : "human" , "content" : "When does the sun come up in the summer?" },
8592 {"role" : "assistant" , "content" : "Usually around 6am." },
0 commit comments