You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support for conversations with message history (#234)
* Add system_instruction parameter
* Add chat_history parameter
* Add missing doc strings
* Open AI
* Add a summary of the chat history to the query embedding
* an extra llm call adds to latency and cost, but including the entire - or even part of - the chat history can potentially create a very large embedding context
* Anthropic
* Change return type of Anthropic get_messages()
* from list to anthropic.MessageParam
* Cohere
* upgrading from Cohere API v1 to API v2, as the v2 is handling chat history in a way that is consistent with the other providers
* Mistral
* VertexAI
* Formatting
* Fix mypy errors
* Ollama
* plus added the `options` parameter to the ollama `chat` call
* Override of the system message
* an idea of how to override the system instructions for some invokations
* Use TYPE_CHECKING for dev dependencies
* Formatting
* Rename `chat_history` to `message_history`
* Use BaseMessage class type
* for the type declaration of the `message_history` parameter
* System instruction override
* Revert BaseMessage class type
* bring back list[dicy[str,str]] type declaration for the `message_history` parameter
* Fix mypy errors
* Update tests
* Fix ollama NameError
* Fix NameError in unit tests
* at the same time as making mypy shut up
* Add TypeDict `LLMMessage`
* to help with the type declaration of the message history
* Simplify the retriever prompt
* Fix E2E tests
* Unit tests for the system instruction override
* Move and rename the prompts
* ... for query embedding and summarization to the GraphRAG class
* Update changelog
* Add missing parameter in example
* Add LLMMessage to the docs
* Update docs README
@@ -26,6 +37,7 @@ class AnthropicLLM(LLMInterface):
26
37
Args:
27
38
model_name (str, optional): Name of the LLM to use. Defaults to "gemini-1.5-flash-001".
28
39
model_params (Optional[dict], optional): Additional parameters passed to the model when text is sent to it. Defaults to None.
40
+
system_instruction: Optional[str], optional): Additional instructions for setting the behavior and context for the model in a conversation. Defaults to None.
29
41
**kwargs (Any): Arguments passed to the model when for the class is initialised. Defaults to None.
30
42
31
43
Raises:
@@ -49,6 +61,7 @@ def __init__(
49
61
self,
50
62
model_name: str,
51
63
model_params: Optional[dict[str, Any]] =None,
64
+
system_instruction: Optional[str] =None,
52
65
**kwargs: Any,
53
66
):
54
67
try:
@@ -58,55 +71,86 @@ def __init__(
58
71
"""Could not import Anthropic Python client.
59
72
Please install it with `pip install "neo4j-graphrag[anthropic]"`."""
Copy file name to clipboardExpand all lines: src/neo4j_graphrag/llm/base.py
+22-5Lines changed: 22 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@
17
17
fromabcimportABC, abstractmethod
18
18
fromtypingimportAny, Optional
19
19
20
-
from .typesimportLLMResponse
20
+
from .typesimportLLMMessage, LLMResponse
21
21
22
22
23
23
classLLMInterface(ABC):
@@ -26,24 +26,34 @@ class LLMInterface(ABC):
26
26
Args:
27
27
model_name (str): The name of the language model.
28
28
model_params (Optional[dict], optional): Additional parameters passed to the model when text is sent to it. Defaults to None.
29
+
system_instruction: Optional[str], optional): Additional instructions for setting the behavior and context for the model in a conversation. Defaults to None.
29
30
**kwargs (Any): Arguments passed to the model when for the class is initialised. Defaults to None.
0 commit comments