From fc67a4effbf094b7d2de500a880ee377c6c708b0 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Tue, 12 Dec 2023 18:54:20 -0800 Subject: [PATCH] Minor logging and formatting changes Add default `llm_bots` configuration to Docker Implement persona support from https://github.com/NeonGeckoCom/neon-llm-core/pull/3 --- Dockerfile | 4 +++- docker_overlay/etc/neon/diana.yaml | 12 +++++++++--- neon_llm_chatgpt/__main__.py | 2 ++ neon_llm_chatgpt/chatgpt.py | 7 ++++--- neon_llm_chatgpt/rmq.py | 11 ++++++++--- requirements/requirements.txt | 4 +++- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 822d628..af2ef09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,10 @@ LABEL vendor=neon.ai \ ENV OVOS_CONFIG_BASE_FOLDER neon ENV OVOS_CONFIG_FILENAME diana.yaml ENV XDG_CONFIG_HOME /config -COPY docker_overlay/ / +ENV CHATBOT_VERSION v2 +COPY docker_overlay/ / +RUN apt update && apt install -y git WORKDIR /app COPY . /app RUN pip install /app diff --git a/docker_overlay/etc/neon/diana.yaml b/docker_overlay/etc/neon/diana.yaml index 3c0fa01..47a2cc4 100644 --- a/docker_overlay/etc/neon/diana.yaml +++ b/docker_overlay/etc/neon/diana.yaml @@ -1,4 +1,4 @@ -log_level: INFO +log_level: DEBUG logs: level_overrides: error: @@ -8,7 +8,7 @@ logs: info: [] debug: [] MQ: - server: api.neon.ai + server: neon-rabbitmq port: 5672 users: mq_handler: @@ -19,4 +19,10 @@ LLM_CHAT_GPT: role: "You are trying to give a short answer in less than 40 words." context_depth: 3 max_tokens: 100 - num_parallel_processes: 2 \ No newline at end of file + num_parallel_processes: 2 +llm_bots: + chat_gpt: + - name: assistant + description: You are a personal assistant who responds in 40 words or less + - name: author + description: You will respond as an author and expert in literary history \ No newline at end of file diff --git a/neon_llm_chatgpt/__main__.py b/neon_llm_chatgpt/__main__.py index e98ff45..55ac1ae 100644 --- a/neon_llm_chatgpt/__main__.py +++ b/neon_llm_chatgpt/__main__.py @@ -25,9 +25,11 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from neon_llm_chatgpt.rmq import ChatgptMQ +from neon_utils.log_utils import init_log def main(): + init_log(log_name="chatgpt") # Run RabbitMQ chatgptMQ = ChatgptMQ() chatgptMQ.run(run_sync=False, run_consumers=True, diff --git a/neon_llm_chatgpt/chatgpt.py b/neon_llm_chatgpt/chatgpt.py index fe378bf..21de273 100644 --- a/neon_llm_chatgpt/chatgpt.py +++ b/neon_llm_chatgpt/chatgpt.py @@ -29,6 +29,7 @@ from typing import List, Dict from neon_llm_core.llm import NeonLLM +from ovos_utils.log import LOG class ChatGPT(NeonLLM): @@ -71,7 +72,7 @@ def _system_prompt(self) -> str: return self.role def warmup(self): - self.model + _ = self.model def get_sorted_answer_indexes(self, question: str, answers: List[str], persona: dict) -> List[int]: """ @@ -102,7 +103,7 @@ def _call_model(self, prompt: List[Dict[str, str]]) -> str: max_tokens=self.max_tokens, ) text = response.choices[0].message['content'] - + LOG.debug(text) return text def _assemble_prompt(self, message: str, chat_history: List[List[str]], persona: dict) -> List[Dict[str, str]]: @@ -153,4 +154,4 @@ def _embeddings(self, question: str, answers: List[str], persona: dict) -> (List embeddings = get_embeddings(texts, engine="text-embedding-ada-002") question_embeddings = embeddings[0] answers_embeddings = embeddings[1:] - return question_embeddings, answers_embeddings \ No newline at end of file + return question_embeddings, answers_embeddings diff --git a/neon_llm_chatgpt/rmq.py b/neon_llm_chatgpt/rmq.py index 3409a95..117b202 100644 --- a/neon_llm_chatgpt/rmq.py +++ b/neon_llm_chatgpt/rmq.py @@ -48,8 +48,13 @@ def model(self): return self._model def warmup(self): - self.model + """ + Initialize this LLM to be ready to provide responses + """ + _ = self.model @staticmethod - def compose_opinion_prompt(respondent_nick: str, question: str, answer: str) -> str: - return f'Why Answer "{answer}" to the Question "{question}" generated by Bot named "{respondent_nick}" is good?' + def compose_opinion_prompt(respondent_nick: str, question: str, + answer: str) -> str: + return (f'Why Answer "{answer}" to the Question "{question}" ' + f'generated by Bot named "{respondent_nick}" is good?') diff --git a/requirements/requirements.txt b/requirements/requirements.txt index e08541f..907ac37 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,4 +1,6 @@ # model openai[embeddings]~=0.27 # networking -neon_llm_core~=0.1.0 \ No newline at end of file +# neon_llm_core~=0.1.0 +neon-llm-core[chatbots]@git+https://github.com/neongeckocom/neon-llm-core@FEAT_ConfigureChatbotPersonas +ovos-utils~=0.0.32 \ No newline at end of file