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.
|
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
|
## Dependancies
|
||||||
|
|
||||||
- [ollama 0.1.14](https://ollama.com/download/linux)
|
- [ollama 0.1.14](https://ollama.com/download/linux)
|
||||||
@ -23,11 +25,13 @@ pip install ollama; pip install ollama-python
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
First Terminal instance
|
First Terminal instance
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
ollama serve
|
ollama serve
|
||||||
```
|
```
|
||||||
|
|
||||||
Second Terminal instance
|
Second Terminal instance
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python ./src/ollama_slixmpp_omemo_bot/main.py
|
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python ./src/ollama_slixmpp_omemo_bot/main.py
|
||||||
# Enter JID: service-account@example-server.im
|
# Enter JID: service-account@example-server.im
|
||||||
@ -41,6 +45,8 @@ Recommended and tested clients:
|
|||||||
- Profanity
|
- Profanity
|
||||||
- You may need to manually trust their fingerprint
|
- 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
|
## 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)
|
[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
|
encrypted, mfrom, allow_untrusted
|
||||||
)
|
)
|
||||||
if body is not None:
|
if body is not None:
|
||||||
decoded = body.decode("utf8")
|
decoded: Optional[str] = body.decode("utf8")
|
||||||
if self.is_command(decoded):
|
if self.is_command(decoded):
|
||||||
await self.handle_command(mto, mtype, decoded)
|
await self.handle_command(mto, mtype, decoded)
|
||||||
elif self.debug_level == LEVEL_DEBUG:
|
elif self.debug_level == LEVEL_DEBUG:
|
||||||
ollama_server_response = self.message_to_ollama_server(decoded)
|
ollama_server_response: Optional[str] = (
|
||||||
await self.encrypted_reply(mto, mtype, f"{ollama_server_response}")
|
self.message_to_ollama_server(decoded)
|
||||||
|
)
|
||||||
|
await self.encrypted_reply(
|
||||||
|
mto, mtype, f"{ollama_server_response or ''}"
|
||||||
|
)
|
||||||
except MissingOwnKey:
|
except MissingOwnKey:
|
||||||
await self.plain_reply(
|
await self.plain_reply(
|
||||||
mto,
|
mto,
|
||||||
@ -130,11 +134,11 @@ class OllamaBot(ClientXMPP):
|
|||||||
f"Error: Your device '{exn.device}' is not in my trusted devices.",
|
f"Error: Your device '{exn.device}' is not in my trusted devices.",
|
||||||
)
|
)
|
||||||
await self.message_handler(msg, allow_untrusted=True)
|
await self.message_handler(msg, allow_untrusted=True)
|
||||||
except (EncryptionPrepareException,):
|
except EncryptionPrepareException:
|
||||||
await self.plain_reply(
|
await self.plain_reply(
|
||||||
mto, mtype, "Error: I was not able to decrypt the message."
|
mto, mtype, "Error: I was not able to decrypt the message."
|
||||||
)
|
)
|
||||||
except (Exception,) as exn:
|
except Exception as exn:
|
||||||
await self.plain_reply(
|
await self.plain_reply(
|
||||||
mto,
|
mto,
|
||||||
mtype,
|
mtype,
|
||||||
@ -191,14 +195,15 @@ class OllamaBot(ClientXMPP):
|
|||||||
)
|
)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def message_to_ollama_server(self, msg: str) -> str:
|
def message_to_ollama_server(self, msg: Optional[str]) -> Optional[str]:
|
||||||
response = ollama.chat(
|
if msg is not None:
|
||||||
model="llama3",
|
response = ollama.chat(
|
||||||
messages=[
|
model="llama3",
|
||||||
{
|
messages=[
|
||||||
"role": "user",
|
{
|
||||||
"content": f"{msg}",
|
"role": "user",
|
||||||
},
|
"content": f"{msg}",
|
||||||
],
|
},
|
||||||
)
|
],
|
||||||
return response["message"]["content"]
|
)
|
||||||
|
return response["message"]["content"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user