defog-ai / sqlcoder

SoTA LLM for converting natural language questions to SQL queries
Apache License 2.0
3.27k stars 205 forks source link

Error In UI Query Database Section #69

Closed oguzhantortop closed 7 months ago

oguzhantortop commented 7 months ago

Hi, I configured my local postgresql database and clicked get tables button indexed an empty customer table.

however on Query Data section when I write "query all customers" I get the following error:

INFO: ::1:52429 - "POST /query HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 404, in run_asgi result = await app( # type: ignore[func-returns-value] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call return await self.app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in call await super().call(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/applications.py", line 123, in call await self.middleware_stack(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in call raise exc File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in call await self.app(scope, receive, _send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/middleware/cors.py", line 91, in call await self.simple_response(scope, receive, send, request_headers=headers) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/middleware/cors.py", line 146, in simple_response await self.app(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/routing.py", line 758, in call await self.middleware_stack(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/routing.py", line 778, in app await route.handle(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/routing.py", line 299, in handle await self.app(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/routing.py", line 79, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/starlette/routing.py", line 74, in app response = await func(request) ^^^^^^^^^^^^^^^^^^^ File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/fastapi/routing.py", line 299, in app raise e File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/fastapi/routing.py", line 294, in app raw_response = await run_endpoint_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/sqlcoder/query_routes.py", line 99, in query ddl = convert_metadata_to_ddl(metadata) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/oguzhan/.pyenv/versions/3.11.7/lib/python3.11/site-packages/sqlcoder/query_routes.py", line 79, in convert_metadata_to_ddl for table_name, columns in metadata.items(): ^^^^^^^^^^^^^^ AttributeError: 'list' object has no attribute 'items'

rishsriv commented 7 months ago

Hi there, you'll have to generate metadata first from the UI! After you get the tables, you'll have to click on the extract metadata button for the model to know what the metadata contains.

Screenshot 2024-02-09 at 02 34 26

We will make this a lot clearer in future versions!

oguzhantortop commented 7 months ago

Hi, I already did this.

image
rishsriv commented 7 months ago

Thank for highlighting this. This an issue with the way the route handling the "Update metadata on server" button was being executed.

Fixed in 0.2.4! Please feel free to reopen if you still run into issues after reinstalling!

pip uninstall sqlcoder
pip install sqlcoder==0.2.4
sqlcoder launch
oguzhantortop commented 7 months ago

Hi, Thank you now it is working. Just a small question is this version of sqlcoder benefits from Apple silicon gpu? Seems to be running little bit slow in Apple M1 Pro (I know that in your documentation it is not stated to be run in M1 Pro but it is very similar to M2 pro)

rishsriv commented 7 months ago

This will be fairly slow, unfortunately. M1 Pro memory bandwidth and GPU cores are a bit more limited -- you'll get much faster performance with a Max or Ultra chip

oguzhantortop commented 7 months ago

In the documentation it is advised to installed for macs like following: CMAKE_ARGS="-DLLAMA_METAL=on" pip install "sqlcoder[llama-cpp]"

sqlcoder==0.2.4 version supports this installation? If so how can I?

rishsriv commented 7 months ago

Hi there, turns out this was because of a change in the latest version of the llama-cpp-python library, and all the GPU cores in Apple Silicon weren't being properly utilized. We have not fixed this in this commit

You should get ~5-10x faster speeds now if you reinstall sqlcoder with the 0.2.5 version!