Update ZepMessageReader and ZepMessageWriter to avoid 404 error (#1844)
* Update ZepMessageReader and ZepMessageWriter to avoid 404 error * Update ZepMessageReader and ZepMessageWriter to use API Base Path option * Update ZepMessageReader and ZepMessageWriter to fix API Base Path and avoid 404 error * Update ZepMessageReader and ZepMessageWriter to use API Base Path option
This commit is contained in:
parent
fa87284937
commit
1a54582b95
2 changed files with 28 additions and 2 deletions
|
|
@ -54,6 +54,10 @@ class ZepMessageReaderComponent(BaseMemoryComponent):
|
|||
"info": "Limit of search results.",
|
||||
"advanced": True,
|
||||
},
|
||||
"api_base_path": {
|
||||
"display_name": "API Base Path",
|
||||
"options": ["api/v1", "api/v2"],
|
||||
},
|
||||
}
|
||||
|
||||
def get_messages(self, **kwargs) -> list[Record]:
|
||||
|
|
@ -108,6 +112,7 @@ class ZepMessageReaderComponent(BaseMemoryComponent):
|
|||
def build(
|
||||
self,
|
||||
session_id: Text,
|
||||
api_base_path: str = "api/v1",
|
||||
url: Optional[Text] = None,
|
||||
api_key: Optional[Text] = None,
|
||||
query: Optional[Text] = None,
|
||||
|
|
@ -118,12 +123,21 @@ class ZepMessageReaderComponent(BaseMemoryComponent):
|
|||
try:
|
||||
from zep_python import ZepClient
|
||||
from zep_python.langchain import ZepChatMessageHistory
|
||||
|
||||
# Monkeypatch API_BASE_PATH to
|
||||
# avoid 404
|
||||
# This is a workaround for the local Zep instance
|
||||
# cloud Zep works with v2
|
||||
import zep_python.zep_client
|
||||
|
||||
zep_python.zep_client.API_BASE_PATH = api_base_path
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import zep-python package. " "Please install it with `pip install zep-python`."
|
||||
)
|
||||
if url == "":
|
||||
url = None
|
||||
|
||||
zep_client = ZepClient(api_url=url, api_key=api_key)
|
||||
memory = ZepChatMessageHistory(session_id=session_id, zep_client=zep_client)
|
||||
records = self.get_messages(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from langflow.base.memory.memory import BaseMemoryComponent
|
||||
from langflow.field_typing import Text
|
||||
|
|
@ -39,6 +38,10 @@ class ZepMessageWriterComponent(BaseMemoryComponent):
|
|||
"display_name": "Input Record",
|
||||
"info": "Record to write to Zep.",
|
||||
},
|
||||
"api_base_path": {
|
||||
"display_name": "API Base Path",
|
||||
"options": ["api/v1", "api/v2"],
|
||||
},
|
||||
}
|
||||
|
||||
def add_message(
|
||||
|
|
@ -77,18 +80,27 @@ class ZepMessageWriterComponent(BaseMemoryComponent):
|
|||
self,
|
||||
input_value: Record,
|
||||
session_id: Text,
|
||||
api_base_path: str = "api/v1",
|
||||
url: Optional[Text] = None,
|
||||
api_key: Optional[Text] = None,
|
||||
) -> Record:
|
||||
try:
|
||||
# Monkeypatch API_BASE_PATH to
|
||||
# avoid 404
|
||||
# This is a workaround for the local Zep instance
|
||||
# cloud Zep works with v2
|
||||
import zep_python.zep_client
|
||||
from zep_python import ZepClient
|
||||
from zep_python.langchain import ZepChatMessageHistory
|
||||
|
||||
zep_python.zep_client.API_BASE_PATH = api_base_path
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import zep-python package. " "Please install it with `pip install zep-python`."
|
||||
)
|
||||
if url == "":
|
||||
url = None
|
||||
|
||||
zep_client = ZepClient(api_url=url, api_key=api_key)
|
||||
memory = ZepChatMessageHistory(session_id=session_id, zep_client=zep_client)
|
||||
self.add_message(**input_value.data, memory=memory)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue