Skip to content

Commit

Permalink
Merge pull request #67 from biocypher/xinference-system-msg
Browse files Browse the repository at this point in the history
adjustment to message appending to account for ..
  • Loading branch information
slobentanzer authored Dec 13, 2023
2 parents fa9cf75 + 8b42346 commit 03b4ae6
Showing 1 changed file with 59 additions and 10 deletions.
69 changes: 59 additions & 10 deletions biochatter/llm_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ def append_system_message(self, message: str):
),
)

def append_ca_message(self, message: str):
self.ca_messages.append(
SystemMessage(
content=message,
),
)

def append_user_message(self, message: str):
self.messages.append(
HumanMessage(
Expand All @@ -133,19 +140,11 @@ def setup(self, context: str):
"""
for msg in self.prompts["primary_model_prompts"]:
if msg:
self.messages.append(
SystemMessage(
content=msg,
),
)
self.append_system_message(msg)

for msg in self.prompts["correcting_agent_prompts"]:
if msg:
self.ca_messages.append(
SystemMessage(
content=msg,
),
)
self.append_ca_message(msg)

self.context = context
msg = f"The topic of the research is {context}."
Expand Down Expand Up @@ -384,6 +383,56 @@ def load_models(self):
# names.append(name)
# return names

def append_system_message(self, message: str):
"""
We override the system message addition because Xinference does not
accept multiple system messages. We concatenate them if there are
multiple.
Args:
message (str): The message to append.
"""
# if there is not already a system message in self.messages
if not any(isinstance(m, SystemMessage) for m in self.messages):
self.messages.append(
SystemMessage(
content=message,
),
)
else:
# if there is a system message, append to the last one
for i, msg in enumerate(self.messages):
if isinstance(msg, SystemMessage):
self.messages[i].content += f"\n{message}"
break

def append_ca_message(self, message: str):
"""
We also override the system message addition for the correcting agent,
likewise because Xinference does not accept multiple system messages. We
concatenate them if there are multiple.
TODO this currently assumes that the correcting agent is the same model
as the primary one.
Args:
message (str): The message to append.
"""
# if there is not already a system message in self.messages
if not any(isinstance(m, SystemMessage) for m in self.ca_messages):
self.ca_messages.append(
SystemMessage(
content=message,
),
)
else:
# if there is a system message, append to the last one
for i, msg in enumerate(self.ca_messages):
if isinstance(msg, SystemMessage):
self.ca_messages[i].content += f"\n{message}"
break

def _primary_query(self):
"""
Expand Down

0 comments on commit 03b4ae6

Please sign in to comment.