Code Monkey home page Code Monkey logo

signal-aichat's Introduction

NOTE

This project is currently archived. The relevant API:s and libraries are constantly shifting, and I don't have time to keep up.


signal-aichat is an AI-powered chatbot for the Signal messenger app. It currently supports:


Setup instructions

0. Clone this repo

git clone https://github.com/cycneuramus/signal-aichat


1. signald

Chatting with your own number via "Note to Self" does not work. This assumes you will be using a separate Signal account for the bot.

Start the signald container:

docker compose up -d signald

Drop into the container's shell:

docker exec -it signal-aichat-signald /bin/bash

Once inside the container, either:

# link to an existing account:
$ signaldctl account link --device-name signal-aichat

or

# register a new account:
$ signaldctl account register [phone number]

For more information, see the documentation for signald.

Once the account is setup, populate the SIGNAL_PHONE_NUMBER variable in the .env file.


2. Google Bard

See the Bard repository. TL;DR:

Go to https://bard.google.com/

  • F12 for console
  • Session: Go to Application -> Cookies -> __Secure-1PSID. Copy the value of that cookie.
  • In .env, populate the BARD_TOKEN variable with the cookie value

3. Bing Chat

See the EdgeGPT repository. TL;DR:

Checking access

  • Install the latest version of Microsoft Edge
  • Alternatively, you can use any browser and set the user-agent to look like you're using Edge (e.g., Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.51). You can do this easily with an extension like "User-Agent Switcher and Manager" for Chrome and Firefox.
  • Open bing.com/chat
  • If you see a chat feature, you are good to go

Getting authentication

  • Install the cookie editor extension for Chrome or Firefox
  • Go to bing.com
  • Open the extension
  • Click "Export" on the bottom right, then "Export as JSON" (this saves your cookies to the clipboard)
  • Paste your cookies into a file named bing.json

Make sure to add the exported JSON to the config/bing.json file in this repo directory.


4. ChatGPT

  • In the .env file, populate the OPENAI_API_KEY variable with your API key
  • Optionally, populate the OPENAI_API_BASE variable to use a different endpoint (defaults to https://api.openai.com/v1)

5. HuggingChat

See the HuggingChat API repository. TL;DR:

  • Install the Cookie-Editor extension for Chrome or Firefox
  • Go to HuggingChat and login
  • Open the extension
  • Click Export on the bottom right, then Export as JSON (this saves your cookies to the clipboard)

Make sure to add the exported JSON to the config/hugchat.json file in this repo directory.


6. Llama models

  • Place your model weights in the models directory
  • In the .env file, change the model in the MODEL path variable to match your model file

7. Additional configuration

In .env:

  • Models can be disabled by populating the DISABLED_MODELS variable
  • To chat with a default model without explicitly having to trigger a bot response with !<model>, populate the DEFAULT_MODEL variable

Assuming DEFAULT_MODEL=gpt, for example, you'd be able to chat normally:


8. Deploy

  • docker compose up -d

And start chatting.

signal-aichat's People

Contributors

cycneuramus avatar github-actions[bot] avatar paulwoitaschek avatar rareromfish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

signal-aichat's Issues

Latest master tag fails

When starting conversations with the image:
image: ghcr.io/cycneuramus/signal-aichat:master

There is no response and in the logs I can see:

Traceback (most recent call last):

  File "/home/signal-aichat/signal-aichat.py", line 6, in <module>

    import ai

  File "/home/signal-aichat/ai.py", line 8, in <module>

    from EdgeGPT import Chatbot as Bing

ImportError: cannot import name 'Chatbot' from 'EdgeGPT' (/home/signal-aichat/.local/lib/python3.10/site-packages/EdgeGPT/__init__.py)

Signal aichat fails to start.

2023-10-12 21:27:53,103 bot: [INFO] Connected to socket (/var/run/signald/signald.sock)
2023-10-12 21:27:53,105 bot: [INFO] Handler registered ('')
2023-10-12 21:27:53,106 bot: [INFO] Bot started
2023-10-12 21:27:53,111 bot: [INFO] Connected to socket (/var/run/signald/signald.sock)
Traceback (most recent call last):
File "/home/abdalnablse/signal-aichat/signal_aichat.py", line 64, in main
await bot.start()
File "/home/abdalnablse/.local/lib/python3.10/site-packages/semaphore/bot.py", line 184, in start
self._receive_socket = await Socket(self._username,
File "/home/abdalnablse/.local/lib/python3.10/site-packages/semaphore/socket.py", line 67, in aenter
self.log.info(f"Bot attempted to subscribe to +********{self._username[-3:]}")
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/abdalnablse/signal-aichat/signal_aichat.py", line 69, in
anyio.run(main)
File "/home/abdalnablse/.local/lib/python3.10/site-packages/anyio/_core/_eventloop.py", line 70, in run
return asynclib.run(func, *args, backend_options)
File "/home/abdalnablse/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 292, in run
return native_run(wrapper(), debug=debug)
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/abdalnablse/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 287, in wrapper
return await func(*args)
File "/home/abdalnablse/signal-aichat/signal_aichat.py", line 58, in main
async with Bot(
File "/home/abdalnablse/.local/lib/python3.10/site-packages/semaphore/bot.py", line 179, in aexit
await self._send_socket.aexit(*excinfo)
File "/home/abdalnablse/.local/lib/python3.10/site-packages/semaphore/socket.py", line 74, in aexit
self.log.info(f"Bot attempted to unsubscribe to +
******{self._username[-3:]}")
TypeError: 'NoneType' object is not subscriptable

How to chat?

Maybe I'm missing something obvious here but I can't get this running.

I want to use only the openai integration.

My compose file looks like this:

version: "3.9"

services:
  signald:
    image: registry.gitlab.com/signald/signald
    container_name: signal-aichat-signald
    restart: unless-stopped
    volumes:
      - ./signald:/signald

  bot:
    image: ghcr.io/cycneuramus/signal-aichat
    container_name: signal-aichat-bot
    restart: unless-stopped
    env_file:
      - .env
    volumes:
      - ./signald:/signald

I had to remove the user: 1000, 1000 else it was showing errors when communicating with the socket

My .env file is this:

SIGNAL_PHONE_NUMBER=+491xxxxxxx
OPENAI_API_KEY=a-i-i
DEFAULT_MODEL=gpt
DISABLED_MODELS=bing llama
OPENAI_API_BASE=https://api.openai.com/v1

After following the steps, the signald container seems to work and logs when I send a message to myself:

Updating permissions on /signald (for info see "migrating from versions before 0.18.0" on https://signald.org/articles/install/docker/)

10:51:26.214 [main] INFO  io.finn.signald.Main - all data migrations complete

10:51:26.218 [main] INFO  io.finn.signald.Main - Binding to socket /signald/signald.sock

10:51:26.283 [main] INFO  io.finn.signald.Main - Started signald 0.23.2

10:51:27.683 [subscribe] INFO  manager-[redacted 33]979 - Created a manager for [redacted 33]979

10:51:28.693 [[redacted 33]979-receiver] INFO  manager-[redacted 33]979 - received sent message transcript from device 2

10:51:46.557 [[redacted 33]979-receiver] INFO  manager-[redacted 33]979 - received sent message transcript from device 2

However the chatbot itself doesn't seem to do anything:

It's logs show:

Traceback (most recent call last):

  File "/home/signal-aichat/signal-aichat.py", line 175, in <module>

    anyio.run(main)

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/anyio/_core/_eventloop.py", line 70, in run

    return asynclib.run(func, *args, **backend_options)

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 292, in run

    return native_run(wrapper(), debug=debug)

  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run

    return loop.run_until_complete(main)

  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete

    return future.result()

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 287, in wrapper

    return await func(*args)

  File "/home/signal-aichat/signal-aichat.py", line 164, in main

    async with Bot(

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/semaphore/bot.py", line 167, in __aenter__

    self._send_socket = await Socket(self._username,

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/semaphore/socket.py", line 51, in __aenter__

    self._socket = await (await anyio.connect_unix(sockets[i])).__aenter__()

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/anyio/_core/_sockets.py", line 251, in connect_unix

    return await get_asynclib().connect_unix(path)

  File "/home/signal-aichat/.local/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 1706, in connect_unix

    raw_socket.connect(path)

ConnectionRefusedError: [Errno 111] Connection refused

2023-05-14 10:51:27,484 bot: [INFO] Connected to socket (/signald/signald.sock)

2023-05-14 10:51:27,484 bot: [INFO] Handler <ai> registered ('')

2023-05-14 10:51:27,485 bot: [INFO] Bot started

2023-05-14 10:51:27,485 bot: [INFO] Connected to socket (/signald/signald.sock)

2023-05-14 10:51:27,485 bot: [INFO] Bot attempted to subscribe to +********525

2023-05-14 10:51:27,485 bot: [INFO] Job queue started

The readme is a bit vague in the final steps:

And start chatting.

So I assume that I have to talk to it using Note to Self but that's not working.
Am I missing something obvious here?

Ollama Support

Any chance of adding support for Ollama?

Not sure if this project is being actively worked on anymore. But I have really enjoyed playing with it to show friends and family a bit about AI without having to setup apps and API keys.

Ollama is another great project for newbies diving into AI.

It would be fantastic to use signal-ai-chat with it.

Thanks for yalls work and effort on this!

Add basic commands to reset the history

Currently, - if I understand correctly - the whole history of messages gets transmitted for the chat completions.
This is problematic because sometimes the context changes:
You might first ask the chat bot for a recipe on how to make a good paella. And then at a later point want to know about the pros and cons of an FSME vaccination.

It would be great if we had the option to reset the history. This could for instance be done with a command like:
!new

That would also have the additional benefit of lowering the costs as there are less tokens (unnecessarily) transmitted.

[ERROR] Processing message (139318381620712) by ai failed

I managed to install the bot.
It was necessary to change the user in docker-compose from 1000:1000 to 0:0.
I added the phone number, connected via qr code.
In .env I added api openai and default_model to gpt.
When I send a message from the same phone number on the group, the console shows:

signal-aichat-signald  | 18:03:25.187 [[redacted 33]9c4-receiver] INFO  manager-[redacted 33]9c4 - received sent message transcript from device 1

But no response appears in the chat.
When I text from another phone number, I get a message in the console:

signal-aichat-bot      | 2023-05-10 18:04:51,988 bot: [INFO] Chat context created for 0g7Ruz0qsQdUFDDUBP5dyVRhodjhmtgK2HX9U/hXyo=+17c52f31-605f-4fe2-862e-5f10e2a6f27e
signal-aichat-bot      | 2023-05-10 18:04:51,988 bot: [ERROR] Processing message (139858331620142) by ai failed
signal-aichat-bot      | Traceback (most recent call last):
signal-aichat-bot      |   File "/home/signal-aichat/.local/lib/python3.10/site-packages/semaphore/bot.py", line 128, in _handle_message
signal-aichat-bot      |     await func(context)
signal-aichat-bot      |   File "/home/signal-aichat/signal-aichat.py", line 52, in ai
signal-aichat-bot      |     ctx.data["bing"] = Chatbot(cookie_path="./cookies.json")
signal-aichat-bot      |   File "/home/signal-aichat/.local/lib/python3.10/site-packages/EdgeGPT.py", line 590, in __init__
signal-aichat-bot      |     self.cookies = json.load(f)
signal-aichat-bot      |   File "/usr/local/lib/python3.10/json/__init__.py", line 293, in load
signal-aichat-bot      |     return loads(fp.read(),
signal-aichat-bot      |   File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
signal-aichat-bot      |     return _default_decoder.decode(s)
signal-aichat-bot      |   File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
signal-aichat-bot      |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
signal-aichat-bot      |   File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
signal-aichat-bot      |     raise JSONDecodeError("Expecting value", s, err.value) from None
signal-aichat-bot      | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

cookies.json mount is error prone

If you setup the volumes like that, and don't have the cookies.json file present, docker will create a cookies.json directory.

This is error prone and will cause confusions.

I suggest you to restructure it so that the cookies.json is in a config folder, i.e. config/cookies.json.
Then you'd bind this as ./config:....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.