Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in latest docker image: SELECT id FROM users #69

Open
zahidhanif opened this issue Sep 26, 2024 · 19 comments
Open

Error in latest docker image: SELECT id FROM users #69

zahidhanif opened this issue Sep 26, 2024 · 19 comments

Comments

@zahidhanif
Copy link

I am getting an error with the latest docker image and the logs say it's having problem with running queries such as SELECT id FROM users. The latest docker image was published earlier today

@zahidhanif
Copy link
Author

zahidhanif commented Sep 26, 2024

Here is the full error:
Traceback (most recent call last):
File "/code/run.py", line 6, in
from func.interactions import *
File "/code/func/interactions.py", line 68, in
allowed_ids = load_allowed_ids_from_db()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/code/func/interactions.py", line 63, in load_allowed_ids_from_db
c.execute("SELECT id FROM users")
sqlite3.OperationalError: no such table: users

@eboye
Copy link

eboye commented Sep 26, 2024

I just tried it and this came up. Same error.

@meligera
Copy link

meligera commented Sep 27, 2024

I executed part where it creates db manually, and it started normally after:

import sqlite3
def init_db():
    conn = sqlite3.connect('users.db')
    c = conn.cursor()
    c.execute('''CREATE TABLE IF NOT EXISTS users
                 (id INTEGER PRIMARY KEY, name TEXT)''')
    c.execute('''CREATE TABLE IF NOT EXISTS chats
                 (id INTEGER PRIMARY KEY AUTOINCREMENT,
                  user_id INTEGER,
                  role TEXT,
                  content TEXT,
                  timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
                  FOREIGN KEY (user_id) REFERENCES users(id))''')
    conn.commit()
    conn.close()
   
init_db()

@Justieku
Copy link

I executed part where it creates db manually, and it started normally after:

import sqlite3
def init_db():
    conn = sqlite3.connect('users.db')
    c = conn.cursor()
    c.execute('''CREATE TABLE IF NOT EXISTS users
                 (id INTEGER PRIMARY KEY, name TEXT)''')
    c.execute('''CREATE TABLE IF NOT EXISTS chats
                 (id INTEGER PRIMARY KEY AUTOINCREMENT,
                  user_id INTEGER,
                  role TEXT,
                  content TEXT,
                  timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
                  FOREIGN KEY (user_id) REFERENCES users(id))''')
    conn.commit()
    conn.close()
   
init_db()

Thank you! Worked for me

@zahidhanif
Copy link
Author

I am using the docker image, so will this be included in the docker build?

@eboye
Copy link

eboye commented Sep 27, 2024

@zahidhanif it's included, but it doesn't run for some reason.

@aliasx
Copy link

aliasx commented Sep 28, 2024

  • Clone Repository
  • Copy this code from run.py:
    c = conn.cursor()
    c.execute('''CREATE TABLE IF NOT EXISTS users
                 (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)''')
    c.execute('''CREATE TABLE IF NOT EXISTS chats
                 (id INTEGER PRIMARY KEY AUTOINCREMENT,
                  user_id INTEGER,
                  role TEXT,
                  content TEXT,
                  timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
                  FOREIGN KEY (user_id) REFERENCES users(id))''')
    conn.commit()

to interactions.py after:

def load_allowed_ids_from_db():
    conn = sqlite3.connect('users.db')
  • Build and run docker compose up --build -d

@eboye
Copy link

eboye commented Sep 28, 2024

I've mapped the users.db volume in yml and made my own empty db, it worked that way.

@zahidhanif
Copy link
Author

I've mapped the users.db volume in yml and made my own empty db, it worked that way.

Can you please send me an example?

@eboye
Copy link

eboye commented Sep 28, 2024

Here's the empty users.db (just extract it to root folder of the project):
users.zip

Docker compose I'm using:

version: '3.8'
services:
  ollama-telegram:
    container_name: ollama-telegram
    image: ruecat/ollama-telegram
    restart: on-failure
    env_file:
      - ./.env
    volumes:
      - ./users.db:/code/users.db

  ollama-server:
    image: ollama/ollama
    container_name: ollama-server
    volumes:
      - ./ollama:/root/.ollama
    restart: always
    ports:
      - '11434:11434'

Once started, I had to execute ollama pull on the ollama-server container like this:

docker exec -it [container_id] ollama pull llama3.2:1b

replace [container_id] with container id from docker ps command of the ollama-server.

And the .env file looks like this:

TOKEN=
ADMIN_IDS=
USER_IDS=
ALLOW_ALL_USERS_IN_GROUPS=1
INITMODEL=llama3.2:1b
TIMEOUT=3000

# UNCOMMENT ONE OF THE FOLLOWING LINES:
# OLLAMA_BASE_URL=localhost # to run ollama without docker, using run.py
OLLAMA_BASE_URL=ollama-server # to run ollama in a docker container 
# OLLAMA_BASE_URL=host.docker.internal # to run ollama locally

OLLAMA_HOST=${OLLAMA_BASE_URL}

# Log level
# https://docs.python.org/3/library/logging.html#logging-levels
LOG_LEVEL=DEBUG

@zahidhanif
Copy link
Author

Here's the empty users.db (just extract it to root folder of the project): users.zip

Docker compose I'm using:

version: '3.8'
services:
  ollama-telegram:
    container_name: ollama-telegram
    image: ruecat/ollama-telegram
    restart: on-failure
    env_file:
      - ./.env
    volumes:
      - ./users.db:/code/users.db

  ollama-server:
    image: ollama/ollama
    container_name: ollama-server
    volumes:
      - ./ollama:/root/.ollama
    restart: always
    ports:
      - '11434:11434'

Once started, I had to execute ollama pull on the ollama-server container like this:

docker exec -it [container_id] ollama pull llama3.2:1b

replace [container_id] with container id from docker ps command of the ollama-server.

And the .env file looks like this:

TOKEN=
ADMIN_IDS=
USER_IDS=
ALLOW_ALL_USERS_IN_GROUPS=1
INITMODEL=llama3.2:1b
TIMEOUT=3000

# UNCOMMENT ONE OF THE FOLLOWING LINES:
# OLLAMA_BASE_URL=localhost # to run ollama without docker, using run.py
OLLAMA_BASE_URL=ollama-server # to run ollama in a docker container 
# OLLAMA_BASE_URL=host.docker.internal # to run ollama locally

OLLAMA_HOST=${OLLAMA_BASE_URL}

# Log level
# https://docs.python.org/3/library/logging.html#logging-levels
LOG_LEVEL=DEBUG

Thanks, that's worked for me

@hhenne1
Copy link

hhenne1 commented Sep 28, 2024

hm.. i'm still getting this after the latest update:
Traceback (most recent call last): File "/code/run.py", line 6, in <module> from func.interactions import * File "/code/func/interactions.py", line 68, in <module> allowed_ids = load_allowed_ids_from_db() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/code/func/interactions.py", line 63, in load_allowed_ids_from_db c.execute("SELECT id FROM users") sqlite3.OperationalError: no such table: users

mapping the db-file just change the error message to something like "can't read users.db"..

@eboye
Copy link

eboye commented Sep 28, 2024

@hhenne1 sounds like permission issue to me. Does docker user has rw access to that file?

@hhenne1
Copy link

hhenne1 commented Sep 30, 2024

oh yea.. im dumb.. my bad, sry.. had a typo in the mount path.. should have realized that docker was mounting an empty folder instead of the file..

@qdii
Copy link

qdii commented Oct 9, 2024

May be related to the comment I left in d3fb767

@qdii
Copy link

qdii commented Oct 9, 2024

Unfortunately, the only existing Docker image is tagged latest (https://hub.docker.com/r/ruecat/ollama-telegram/tags?ordering=-last_updated), so there is no possibility to rollback.

@fredix
Copy link
Contributor

fredix commented Oct 13, 2024

Hi folks !
I fixed this bug, so I will send a PR ASAP, in the meantime you can use my own image : fredix/ollama-telegram

I have removed allowed_ids = load_allowed_ids_from_db() in bot/func/interactions.py and added allowed_ids = load_allowed_ids_from_db() after init_db() in bot/run.py

For those like me that use their own ollama server, you have to know that OLLAMA_BASE_URL must contain the IP of your server and not HTTP://IP

fredix added a commit to fredix/ollama-telegram that referenced this issue Oct 13, 2024
fredix added a commit to fredix/ollama-telegram that referenced this issue Oct 14, 2024
@haydonryan
Copy link

I just tried to install this from scratch... I'm still getting the errors:

$ docker-compose logs -f
ollama-telegram  | Traceback (most recent call last):
ollama-telegram  |   File "/code/run.py", line 6, in <module>
ollama-telegram  |     from func.interactions import *
ollama-telegram  |   File "/code/func/interactions.py", line 68, in <module>
ollama-telegram  |     allowed_ids = load_allowed_ids_from_db()
ollama-telegram  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
ollama-telegram  |   File "/code/func/interactions.py", line 63, in load_allowed_ids_from_db
ollama-telegram  |     c.execute("SELECT id FROM users")
ollama-telegram  | sqlite3.OperationalError: no such table: users
ollama-telegram  | Traceback (most recent call last):
ollama-telegram  |   File "/code/run.py", line 6, in <module>
ollama-telegram  |     from func.interactions import *
ollama-telegram  |   File "/code/func/interactions.py", line 68, in <module>
ollama-telegram  |     allowed_ids = load_allowed_ids_from_db()
ollama-telegram  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
ollama-telegram  |   File "/code/func/interactions.py", line 63, in load_allowed_ids_from_db
ollama-telegram  |     c.execute("SELECT id FROM users")
ollama-telegram  | sqlite3.OperationalError: no such table: users
ollama-telegram  | Traceback (most recent call last):
ollama-telegram  |   File "/code/run.py", line 6, in <module>
ollama-telegram  |     from func.interactions import *
ollama-telegram  |   File "/code/func/interactions.py", line 68, in <module>
ollama-telegram  |     allowed_ids = load_allowed_ids_from_db()
ollama-telegram  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
ollama-telegram  |   File "/code/func/interactions.py", line 63, in load_allowed_ids_from_db

Has the changes been pushed to docker hub?

@GDGooD
Copy link

GDGooD commented Oct 25, 2024

Here is hotfix patch based on @fredix solution.
Use with git apply hotfix-db-users.patch.txt
hotfix-db-users.patch.txt

ruecat added a commit that referenced this issue Oct 28, 2024
fixed issue #69 : sqlite do not init database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants