ericmjl / llamabot

Pythonic class-based interface to LLMs
https://ericmjl.github.io/llamabot/
116 stars 20 forks source link

Getting an SQL error running a CLI command #106

Closed AllenDowney closed 1 week ago

AllenDowney commented 1 week ago

Running llamabot docs write on Azure, I'm getting a gigantic traceback that ends with a SQL error trying to create a table for the message_log.

Here are the parts of the traceback that seem most likely to be useful.

Maybe something went wrong installing sqlite?

OperationalError: database is locked

The above exception was the direct cause of the following exception:

╭──────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────────────────────────────╮

│ /anaconda/envs/fuelight/lib/python3.10/site-packages/llamabot/cli/docs.py:308 in write                                                                                                    │

│                                                                                                                                                                                           │

│   305 │   │   src_file.post.content = ""                                                                                                                                                  │

│   306 │                                                                                                                                                                                   │

│   307 │   ood_checker = ood_checker_bot(model_name=ood_checker_model_name)                                                                                                                │

│ ❱ 308 │   result: DocsOutOfDate = ood_checker(                                                                                                                                            │

│   309 │   │   documentation_information(src_file), verbose=verbose                                                                                                                        │

│   310 │   )                                                                                                                                                                               │

│   311                                                                                                                                                                                     │

│                                                                                                                                                                                           │

│ ╭────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────╮                                                    │

│ │   docwriter_model_name = 'gpt-4o'                                                                                                  │                                                    │

│ │              file_path = PosixPath('customer_level_model.md')                                                                      │                                                    │

│ │           from_scratch = False                                                                                                     │                                                    │

│ │            ood_checker = <llamabot.bot.structuredbot.StructuredBot object at 0x7f4488277e50>                                       │                                                    │

│ │ ood_checker_model_name = 'gpt-4o'                                                                                                  │                                                    │

│ │                 refine = False                                                                                                     │                                                    │

│ │     refiner_model_name = 'o1-preview'                                                                                              │                                                    │

│ │               src_file = MarkdownSourceFile(                                                                                       │                                                    │

│ │                          │   file_path=PosixPath('customer_level_model.md'),                                                       │                                                    │

│ │                          │   post=<frontmatter.Post object at 0x7f44880a4250>,                                                     │                                                    │

│ │                          │   linked_files={},                                                                                      │                                                    │

│ │                          │   raw_content='1: ---\n2: Intents:\n3: -   Explain this notebook\n4: Files:\n5: - ../models/custome'+26 │                                                    │

│ │                          )                                                                                                         │                                                    │

│ │                verbose = False                                                                                                     │                                                    │

│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                    │

│                                                                                                                                                                                           │

│ /anaconda/envs/fuelight/lib/python3.10/site-packages/llamabot/bot/structuredbot.py:109 in __call__                                                                                        │

│                                                                                                                                                                                           │

│   106 │   │   │   try:                                                                                                                                                                    │

│   107 │   │   │   │   match self.stream_target:                                                                                                                                           │

│   108 │   │   │   │   │   case "stdout":                                                                                                                                                  │

│ ❱ 109 │   │   │   │   │   │   response = self.stream_stdout(messages)                                                                                                                     │

│   110 │   │   │   │   │   case "none":                                                                                                                                                    │

│   111 │   │   │   │   │   │   response = self.stream_none(messages)                                                                                                                       │

│   112                                                                                                                                                                                     │

│                    
│ ╭───────────────────────────────────────────────── locals ──────────────────────────────────────────────────╮                                                                             │
│ │    context = <sqlalchemy.dialects.sqlite.base.SQLiteExecutionContext object at 0x7f4481e7a380>            │                                                                             │
│ │     cursor = <sqlite3.Cursor object at 0x7f4484982540>                                                    │                                                                             │
│ │ parameters = ()                                                                                           │                                                                             │
│ │       self = <sqlalchemy.dialects.sqlite.pysqlite.SQLiteDialect_pysqlite object at 0x7f44849a5ea0>        │                                                                             │
│ │  statement = '\nCREATE TABLE message_log (\n\tid INTEGER NOT NULL, \n\tobject_name VARCHAR, \n\ttimes'+99 │                                                                             │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯                                                                             │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
OperationalError: (sqlite3.OperationalError) database is locked
[SQL: 
CREATE TABLE message_log (
        id INTEGER NOT NULL, 
        object_name VARCHAR, 
        timestamp VARCHAR, 
        message_log TEXT, 
        model_name VARCHAR, 
        temperature FLOAT, 
        PRIMARY KEY (id)
)

]
ericmjl commented 1 week ago

@AllenDowney mmm, this is related to some new features I started adding to LlamaBot. It may be prudent to pin to an older version of LlamaBot, I think. Can you revert back to version 0.8.2 please?

Meanwhile, I'm going to introduce a few more tests related to this bug.

ericmjl commented 1 week ago

For context, I added functionality to automatically log messages sent (including prompts) + responses in a local database that exists in a code repository. The way this is implemented is by writing to a sqlite database locally. I may need to change the default behaviour of how we access the database, as there may be concurrent writes happening that need to be staggered.

ericmjl commented 1 week ago

@AllenDowney I merged in and released a new version of llamabot that I think addresses this issue. It is version 0.8.8. Could you give that a try and see whether this helps address the SQL error?