diff --git a/README.md b/README.md index 30e557c..bc9ab39 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ A basic echo-bot built with slixmpp and slixmpp-omemo that relays your messages to a locally running ollama server with end to end encryption. + + ## Dependancies - [ollama 0.1.14](https://ollama.com/download/linux) @@ -23,11 +25,13 @@ pip install ollama; pip install ollama-python ## Usage First Terminal instance + ```bash ollama serve ``` Second Terminal instance + ```bash PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python ./src/ollama_slixmpp_omemo_bot/main.py # Enter JID: service-account@example-server.im @@ -41,6 +45,8 @@ Recommended and tested clients: - Profanity - You may need to manually trust their fingerprint +Typically when MissingOwnKeys exception raises, starting a new omemo session and manually trusting the fingerprint tends to resolve the issue. + ## Credit [Slixmpp OMEMO plugin | Copyright (C) 2010 Nathanael C. Fritz | Copyright (C) 2019 Maxime “pep” Buquet ](https://codeberg.org/sxavier/slixmpp-omemo/src/branch/main/examples/echo_client.py) diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/docs/index.html @@ -0,0 +1 @@ + diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index e69de29..0000000 diff --git a/docs/ollama_slixmpp_omemo_bot.png b/docs/ollama_slixmpp_omemo_bot.png new file mode 100644 index 0000000..77d9897 Binary files /dev/null and b/docs/ollama_slixmpp_omemo_bot.png differ diff --git a/src/ollama_slixmpp_omemo_bot/ollama_bot.py b/src/ollama_slixmpp_omemo_bot/ollama_bot.py index 0a0c8e2..1ca0c4a 100644 --- a/src/ollama_slixmpp_omemo_bot/ollama_bot.py +++ b/src/ollama_slixmpp_omemo_bot/ollama_bot.py @@ -105,12 +105,16 @@ class OllamaBot(ClientXMPP): encrypted, mfrom, allow_untrusted ) if body is not None: - decoded = body.decode("utf8") + decoded: Optional[str] = body.decode("utf8") if self.is_command(decoded): await self.handle_command(mto, mtype, decoded) elif self.debug_level == LEVEL_DEBUG: - ollama_server_response = self.message_to_ollama_server(decoded) - await self.encrypted_reply(mto, mtype, f"{ollama_server_response}") + ollama_server_response: Optional[str] = ( + self.message_to_ollama_server(decoded) + ) + await self.encrypted_reply( + mto, mtype, f"{ollama_server_response or ''}" + ) except MissingOwnKey: await self.plain_reply( mto, @@ -130,11 +134,11 @@ class OllamaBot(ClientXMPP): f"Error: Your device '{exn.device}' is not in my trusted devices.", ) await self.message_handler(msg, allow_untrusted=True) - except (EncryptionPrepareException,): + except EncryptionPrepareException: await self.plain_reply( mto, mtype, "Error: I was not able to decrypt the message." ) - except (Exception,) as exn: + except Exception as exn: await self.plain_reply( mto, mtype, @@ -191,14 +195,15 @@ class OllamaBot(ClientXMPP): ) raise - def message_to_ollama_server(self, msg: str) -> str: - response = ollama.chat( - model="llama3", - messages=[ - { - "role": "user", - "content": f"{msg}", - }, - ], - ) - return response["message"]["content"] + def message_to_ollama_server(self, msg: Optional[str]) -> Optional[str]: + if msg is not None: + response = ollama.chat( + model="llama3", + messages=[ + { + "role": "user", + "content": f"{msg}", + }, + ], + ) + return response["message"]["content"]