added example picture and additional type safety
This commit is contained in:
parent
ecd88a8267
commit
9207e1c992
@ -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.
|
||||
|
||||
<img src="./docs/ollama_slixmpp_omemo_bot.png" width="250">
|
||||
|
||||
## 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 <pep@bouah.net>](https://codeberg.org/sxavier/slixmpp-omemo/src/branch/main/examples/echo_client.py)
|
||||
|
1
docs/index.html
Normal file
1
docs/index.html
Normal file
@ -0,0 +1 @@
|
||||
|
BIN
docs/ollama_slixmpp_omemo_bot.png
Normal file
BIN
docs/ollama_slixmpp_omemo_bot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 192 KiB |
@ -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"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user