From 9008bc8cff27f9864f19b947a5709013666a2635 Mon Sep 17 00:00:00 2001 From: NeonBohdan Date: Sun, 29 Oct 2023 13:01:21 +0200 Subject: [PATCH 1/3] Added persona to rmq --- neon_llm_core/rmq.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/neon_llm_core/rmq.py b/neon_llm_core/rmq.py index 69b7ea6..6c76ffb 100644 --- a/neon_llm_core/rmq.py +++ b/neon_llm_core/rmq.py @@ -106,9 +106,10 @@ def handle_request(self, body: dict): query = body["query"] history = body["history"] + persona = body.get("persona",{}) try: - response = self.model.ask(message=query, chat_history=history) + response = self.model.ask(message=query, chat_history=history, persona=persona) except ValueError as err: LOG.error(f'ValueError={err}') response = 'Sorry, but I cannot respond to your message at the moment, please try again later' @@ -131,12 +132,13 @@ def handle_score_request(self, body: dict): query = body["query"] responses = body["responses"] + persona = body.get("persona",{}) if not responses: sorted_answer_indexes = [] else: try: - sorted_answer_indexes = self.model.get_sorted_answer_indexes(question=query, answers=responses) + sorted_answer_indexes = self.model.get_sorted_answer_indexes(question=query, answers=responses, persona=persona) except ValueError as err: LOG.error(f'ValueError={err}') sorted_answer_indexes = [] @@ -159,17 +161,19 @@ def handle_opinion_request(self, body: dict): query = body["query"] options = body["options"] + persona = body.get("persona",{}) responses = list(options.values()) if not responses: opinion = "Sorry, but I got no options to choose from." else: try: - sorted_answer_indexes = self.model.get_sorted_answer_indexes(question=query, answers=responses) + sorted_answer_indexes = self.model.get_sorted_answer_indexes(question=query, answers=responses, persona=persona) best_respondent_nick, best_response = list(options.items())[sorted_answer_indexes[0]] opinion = self._ask_model_for_opinion(respondent_nick=best_respondent_nick, question=query, - answer=best_response) + answer=best_response, + persona=persona) except ValueError as err: LOG.error(f'ValueError={err}') opinion = "Sorry, but I experienced an issue trying to make up an opinion on this topic" @@ -183,11 +187,11 @@ def handle_opinion_request(self, body: dict): queue=routing_key) LOG.info(f"Handled ask request for message_id={message_id}") - def _ask_model_for_opinion(self, respondent_nick: str, question: str, answer: str) -> str: + def _ask_model_for_opinion(self, respondent_nick: str, question: str, answer: str, persona: dict) -> str: prompt = self.compose_opinion_prompt(respondent_nick=respondent_nick, question=question, answer=answer) - opinion = self.model.ask(message=prompt, chat_history=[]) + opinion = self.model.ask(message=prompt, chat_history=[], persona=persona) LOG.info(f'Received LLM opinion={opinion}, prompt={prompt}') return opinion From ce4f2c0c53a13964648b10be33f44ba952592973 Mon Sep 17 00:00:00 2001 From: NeonBohdan Date: Sun, 29 Oct 2023 13:08:47 +0200 Subject: [PATCH 2/3] Added persona to llm --- neon_llm_core/llm.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neon_llm_core/llm.py b/neon_llm_core/llm.py index 773e384..390569c 100644 --- a/neon_llm_core/llm.py +++ b/neon_llm_core/llm.py @@ -60,14 +60,14 @@ def llm_model_name(self) -> str: def _system_prompt(self) -> str: pass - def ask(self, message: str, chat_history: List[List[str]]) -> str: + def ask(self, message: str, chat_history: List[List[str]], persona: dict) -> str: """ Generates llm response based on user message and (user, llm) chat history """ - prompt = self._assemble_prompt(message, chat_history) + prompt = self._assemble_prompt(message, chat_history, persona) llm_text_output = self._call_model(prompt) return llm_text_output @abstractmethod - def get_sorted_answer_indexes(self, question: str, answers: List[str]) -> List[int]: + def get_sorted_answer_indexes(self, question: str, answers: List[str], persona: dict) -> List[int]: """ Creates sorted list of answer indexes with respect to order provided in :param answers Results should be sorted from best to worst @@ -87,7 +87,7 @@ def _call_model(self, prompt: str) -> str: pass @abstractmethod - def _assemble_prompt(self, message: str, chat_history: List[List[str]]): + def _assemble_prompt(self, message: str, chat_history: List[List[str]], persona: dict): """ Assembles prompt engineering logic From 48afd40fc8d014fa8c86fc36172e91918736828d Mon Sep 17 00:00:00 2001 From: NeonBohdan Date: Sun, 29 Oct 2023 13:25:42 +0200 Subject: [PATCH 3/3] Increment Version to 0.1.0 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 6c3504c..4488dcb 100644 --- a/version.py +++ b/version.py @@ -26,4 +26,4 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "0.0.6" +__version__ = "0.1.0"