-
Notifications
You must be signed in to change notification settings - Fork 5
fix: SQL Context 에러 수정 및 Streamlit UI 파싱 수정, 웹페이지 클리닝 #91
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
Open
ParkGyeongTae
wants to merge
1
commit into
master
Choose a base branch
from
feature/87-fix-context-error-and-clean-streamlit-ui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: SQL Context 에러 수정 및 Streamlit UI 파싱 수정, 웹페이지 클리닝 #91
ParkGyeongTae
wants to merge
1
commit into
master
from
feature/87-fix-context-error-and-clean-streamlit-ui
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res["generated_query"]의 리턴값이 문자열일때도 있고, AIMessage일때도 있는 현상 해결함. 2025-05-02 11:46:52 [INFO] Successfully connected to ClickHouse.
2025-05-02 11:46:52 [INFO] Loading faiss with AVX2 support.
2025-05-02 11:46:52 [INFO] Successfully loaded faiss with AVX2 support.
2025-05-02 11:46:52 [INFO] Failed to load GPU Faiss: name 'GpuIndexIVFFlat' is not defined. Will not load constructor refs for GPU indexes.
2025-05-02 11:46:54 [INFO] HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"
2025-05-02 11:46:55 [INFO] HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
2025-05-02 11:46:58 [INFO] HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
content='<SQL>\n```sql\n SELECT COUNT(DISTINCT entity_id)\n FROM client_stream_ordered_service\n WHERE activity_ts >= date_sub(now(), interval 3 month)\n AND (JSON_CONTAINS(feature_json, \'"service1"\')\n OR JSON_CONTAINS(feature_json, \'"service2"\')\n OR JSON_CONTAINS(feature_json, \'"service3"\'))\n```\n\n<해석>\n```plaintext\n 이 쿼리는 client_stream_ordered_service 테이블에서 최근 3개월 동안 service1, service2, service3\n 중 하나의 서비스를 주문한 고객의 고유한 수를 계산합니다.\n activity_ts 컬럼을 이용해 최근 3개월로 기간을 제한하고, feature_json 컬럼에서 지정된 서비스를\n 포함하고 있는지 확인하여 필터링합니다. entity_id 컬럼을 사용하여 고유 고객 수를 집계합니다.\n```' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 191, 'prompt_tokens': 935, 'total_tokens': 1126, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_55d88aaf2f', 'finish_reason': 'stop', 'logprobs': None} id='run-dc9b75e6-0230-4ab0-a7d3-509844036057-0' usage_metadata={'input_tokens': 935, 'output_tokens': 191, 'total_tokens': 1126, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}
2025-05-02 11:46:59 [ERROR] An error occurred while executing SQL: 'AIMessage' object has no attribute 'encode'
Traceback (most recent call last):
File "/Users/pgt0409/Desktop/git/Lang2SQL/llm_utils/connect_db.py", line 95, in run_sql
result = self.client.execute(sql, with_column_types=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 382, in execute
rv = self.process_ordinary_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 577, in process_ordinary_query
self.connection.send_query(query, query_id=query_id, params=params)
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/connection.py", line 723, in send_query
write_binary_str(query, self.fout)
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/writer.py", line 15, in write_binary_str
text = text.encode('utf-8')
^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/pydantic/main.py", line 891, in __getattr__
raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'AIMessage' object has no attribute 'encode'
2025-05-02 11:46:59.458 Uncaught app execution
Traceback (most recent call last):
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
result = func()
^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
exec(code, module.__dict__)
File "/Users/pgt0409/Desktop/git/Lang2SQL/interface/streamlit_app.py", line 75, in <module>
st.navigation(pages).run()
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/streamlit/navigation/page.py", line 303, in run
exec(code, module.__dict__)
File "/Users/pgt0409/Desktop/git/Lang2SQL/interface/lang2sql.py", line 187, in <module>
display_result(res=result, database=db)
File "/Users/pgt0409/Desktop/git/Lang2SQL/interface/lang2sql.py", line 120, in display_result
df = database.run_sql(sql)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/Desktop/git/Lang2SQL/llm_utils/connect_db.py", line 95, in run_sql
result = self.client.execute(sql, with_column_types=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 382, in execute
rv = self.process_ordinary_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 577, in process_ordinary_query
self.connection.send_query(query, query_id=query_id, params=params)
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/connection.py", line 723, in send_query
write_binary_str(query, self.fout)
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/writer.py", line 15, in write_binary_str
text = text.encode('utf-8')
^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/pydantic/main.py", line 891, in __getattr__
raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'AIMessage' object has no attribute 'encode' |
쿼리를 실행하는 부분에 간헐적으로 한글이 같이 껴있는 현상 수정. 2025-05-02 11:56:00 [INFO] Successfully connected to ClickHouse.
2025-05-02 11:56:01 [INFO] HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"
2025-05-02 11:56:02 [INFO] HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
2025-05-02 11:56:05 [INFO] HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
2025-05-02 11:56:05 [ERROR] An error occurred while executing SQL: Code: 62.
DB::Exception: Unrecognized token: Syntax error: failed at position 343 (해) (line 10, col 2): 해석>
plaintext
이 쿼리는 client_stream_ordered_service 테이블에서 최근 1개월 동안의 데이터를 기준으로
각 서비스별('service1', 'service2', 'service3') ... . Stack trace:
0. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000f48e57b
1. DB::Exception::createDeprecated(String const&, int, bool) @ 0x000000000f5528cd
2. DB::parseQueryAndMovePosition(DB::IParser&, char const*&, char const*, String const&, bool, unsigned long, unsigned long, unsigned long) @ 0x0000000015730f72
3. DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*, std::shared_ptr<DB::IAST>&) @ 0x00000000138fc873
4. DB::executeQuery(String const&, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x00000000138fbba4
5. DB::TCPHandler::runImpl() @ 0x0000000014c2aaec
6. DB::TCPHandler::run() @ 0x0000000014c48cd9
7. Poco::Net::TCPServerConnection::start() @ 0x00000000183727c7
8. Poco::Net::TCPServerDispatcher::run() @ 0x0000000018372c19
9. Poco::PooledThread::run() @ 0x000000001833ef5b
10. Poco::ThreadImpl::runnableEntry(void*) @ 0x000000001833d43d
11. ? @ 0x00007f1fb820eac3
12. ? @ 0x00007f1fb829fa04
Traceback (most recent call last):
File "/Users/pgt0409/Desktop/git/Lang2SQL/llm_utils/connect_db.py", line 95, in run_sql
result = self.client.execute(sql, with_column_types=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 382, in execute
rv = self.process_ordinary_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 580, in process_ordinary_query
return self.receive_result(with_column_types=with_column_types,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 212, in receive_result
return result.get_result()
^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/result.py", line 50, in get_result
for packet in self.packet_generator:
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 228, in packet_generator
packet = self.receive_packet()
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 245, in receive_packet
raise packet.exception
clickhouse_driver.errors.ServerException: Code: 62.
DB::Exception: Unrecognized token: Syntax error: failed at position 343 (해) (line 10, col 2): 해석>
plaintext
이 쿼리는 client_stream_ordered_service 테이블에서 최근 1개월 동안의 데이터를 기준으로
각 서비스별('service1', 'service2', 'service3') ... . Stack trace:
0. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000f48e57b
1. DB::Exception::createDeprecated(String const&, int, bool) @ 0x000000000f5528cd
2. DB::parseQueryAndMovePosition(DB::IParser&, char const*&, char const*, String const&, bool, unsigned long, unsigned long, unsigned long) @ 0x0000000015730f72
3. DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*, std::shared_ptr<DB::IAST>&) @ 0x00000000138fc873
4. DB::executeQuery(String const&, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x00000000138fbba4
5. DB::TCPHandler::runImpl() @ 0x0000000014c2aaec
6. DB::TCPHandler::run() @ 0x0000000014c48cd9
7. Poco::Net::TCPServerConnection::start() @ 0x00000000183727c7
8. Poco::Net::TCPServerDispatcher::run() @ 0x0000000018372c19
9. Poco::PooledThread::run() @ 0x000000001833ef5b
10. Poco::ThreadImpl::runnableEntry(void*) @ 0x000000001833d43d
11. ? @ 0x00007f1fb820eac3
12. ? @ 0x00007f1fb829fa04
2025-05-02 11:56:05.752 Uncaught app execution
Traceback (most recent call last):
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
result = func()
^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
exec(code, module.__dict__)
File "/Users/pgt0409/Desktop/git/Lang2SQL/interface/streamlit_app.py", line 75, in <module>
st.navigation(pages).run()
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/streamlit/navigation/page.py", line 303, in run
exec(code, module.__dict__)
File "/Users/pgt0409/Desktop/git/Lang2SQL/interface/lang2sql.py", line 188, in <module>
display_result(res=result, database=db)
File "/Users/pgt0409/Desktop/git/Lang2SQL/interface/lang2sql.py", line 121, in display_result
df = database.run_sql(sql)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/Desktop/git/Lang2SQL/llm_utils/connect_db.py", line 95, in run_sql
result = self.client.execute(sql, with_column_types=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 382, in execute
rv = self.process_ordinary_query(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 580, in process_ordinary_query
return self.receive_result(with_column_types=with_column_types,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 212, in receive_result
return result.get_result()
^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/result.py", line 50, in get_result
for packet in self.packet_generator:
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 228, in packet_generator
packet = self.receive_packet()
^^^^^^^^^^^^^^^^^^^^^
File "/Users/pgt0409/opt/anaconda3/envs/lang2sql/lib/python3.12/site-packages/clickhouse_driver/client.py", line 245, in receive_packet
raise packet.exception
clickhouse_driver.errors.ServerException: Code: 62.
DB::Exception: Unrecognized token: Syntax error: failed at position 343 (해) (line 10, col 2): 해석>
plaintext
이 쿼리는 client_stream_ordered_service 테이블에서 최근 1개월 동안의 데이터를 기준으로
각 서비스별('service1', 'service2', 'service3') ... . Stack trace:
0. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000000f48e57b
1. DB::Exception::createDeprecated(String const&, int, bool) @ 0x000000000f5528cd
2. DB::parseQueryAndMovePosition(DB::IParser&, char const*&, char const*, String const&, bool, unsigned long, unsigned long, unsigned long) @ 0x0000000015730f72
3. DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*, std::shared_ptr<DB::IAST>&) @ 0x00000000138fc873
4. DB::executeQuery(String const&, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum) @ 0x00000000138fbba4
5. DB::TCPHandler::runImpl() @ 0x0000000014c2aaec
6. DB::TCPHandler::run() @ 0x0000000014c48cd9
7. Poco::Net::TCPServerConnection::start() @ 0x00000000183727c7
8. Poco::Net::TCPServerDispatcher::run() @ 0x0000000018372c19
9. Poco::PooledThread::run() @ 0x000000001833ef5b
10. Poco::ThreadImpl::runnableEntry(void*) @ 0x000000001833d43d
11. ? @ 0x00007f1fb820eac3
12. ? @ 0x00007f1fb829fa04 |
ehddnr301
approved these changes
May 5, 2025
@ehddnr301 확인해주셔서 감사합니다~~! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#️⃣ Issue Number
📝 요약(Summary)
💬 To Reviewers (선택)
PR Checklist
reference) How to Code Review