Skip to content

Commit

Permalink
Added add_messages to make bulk load from LibreChat.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Karmazin committed Jun 6, 2024
1 parent c3dbd24 commit 04b92d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions just_agents/llm_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ def instruct(self, prompt: str):
self.memory.add_message(system_instruction, True)
return system_instruction

def query(self, prompt: str, stream: bool = False, run_callbacks: bool = True, output: Optional[Path] = None) -> str:
def query(self, prompt: str = None, stream: bool = False, run_callbacks: bool = True, output: Optional[Path] = None) -> str:
"""
Query large language model
:param prompt:
:param stream:
:param run_callbacks:
:return:
"""
question = Message(role="user", content=prompt)
self.memory.add_message(question)
if prompt is not None:
question = Message(role="user", content=prompt)
self.memory.add_message(question)
options: Dict = self.llm_options
response: ModelResponse = completion(messages=self.memory.messages, stream=stream, **options)
self._process_response(response)
Expand Down
11 changes: 10 additions & 1 deletion just_agents/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ def add_message(self, message: Message, run_callbacks: bool = True):

@property
def last_message(self) -> Optional[Message]:
return self.messages[-1] if len(self.messages) > 0 else None
return self.messages[-1] if len(self.messages) > 0 else None


def add_messages(self, messages: list, run_callbacks: bool = True):
for message in messages:
msg = Message(content=message["content"], role=message["role"])
self.messages.append(msg)
if run_callbacks:
for handler in self.on_message:
handler(message)

0 comments on commit 04b92d0

Please sign in to comment.