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

fix sql not found error for chat data #2152

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

GITHUBear
Copy link
Contributor

@GITHUBear GITHUBear commented Nov 22, 2024

Description

Fixed the issue that the chat data function occasionally raises "Can not find sql in response" error when there is the answer in the context.
截屏2024-11-22 17 52 02

How Has This Been Tested?

  • Chat Data
  • make test

Snapshots:

Checklist:

  • My code follows the style guidelines of this project
  • I have already rebased the commits and make the commit message conform to the project standard.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published in downstream modules

@github-actions github-actions bot added the fix Bug fixes label Nov 22, 2024
Copy link
Collaborator

@Aries-ckt Aries-ckt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. r+

@priyamshah112
Copy link

Attempted your pull request changes and ran into following issues
image

Get prompt template of scene_name: chat_with_db_execute with model_name: vicuna-13b-v1.5, proxyllm_backend: None, language: en
--- Logging error ---
Traceback (most recent call last):
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/openapi/api_v1/api_v1.py", line 537, in chat_completions
    chat: BaseChat = await get_chat_instance(dialogue)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/openapi/api_v1/api_v1.py", line 440, in get_chat_instance
    chat: BaseChat = await blocking_func_to_async(
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/util/executor_utils.py", line 67, in blocking_func_to_async
    return await loop.run_in_executor(executor, run_with_context)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/util/executor_utils.py", line 64, in run_with_context
    return ctx.run(partial(func, *args, **kwargs))
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/scene/chat_factory.py", line 36, in get_implementation
    implementation = cls(**kwargs)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/scene/chat_db/auto_execute/chat.py", line 34, in __init__
    raise ValueError(
ValueError: <bound method ChatScene.value of <ChatScene.ChatWithDbExecute: <dbgpt.app.scene.base.Scene object at 0x7d3858dbd660>>> mode should chose db!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 678, in format
    record.message = record.getMessage()
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 368, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/dbgpt_server.py", line 289, in <module>
    run_webserver()
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/dbgpt_server.py", line 285, in run_webserver
    run_uvicorn(param)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/dbgpt_server.py", line 245, in run_uvicorn
    uvicorn.run(
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/uvicorn/main.py", line 579, in run
    server.run()
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/middleware/base.py", line 149, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/openapi/api_v1/api_v1.py", line 552, in chat_completions
    logger.exception(f"Chat Exception!{dialogue}", e)
Message: 'Chat Exception!conv_uid=\'0012343e-a909-11ef-bcc9-08bfb8168874\' user_input=\'What is the email address of the user named "Alice Smith"?\' user_name=\'001\' chat_mode=\'chat_with_db_execute\' app_code=\'chat_with_db_execute\' temperature=0.5 select_param=\'\' model_name=\'vicuna-13b-v1.5\' incremental=False sys_code=None ext_info={}'
Arguments: (ValueError('<bound method ChatScene.value of <ChatScene.ChatWithDbExecute: <dbgpt.app.scene.base.Scene object at 0x7d3858dbd660>>> mode should chose db!'),)
--- Logging error ---
Traceback (most recent call last):
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/openapi/api_v1/api_v1.py", line 537, in chat_completions
    chat: BaseChat = await get_chat_instance(dialogue)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/openapi/api_v1/api_v1.py", line 440, in get_chat_instance
    chat: BaseChat = await blocking_func_to_async(
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/util/executor_utils.py", line 67, in blocking_func_to_async
    return await loop.run_in_executor(executor, run_with_context)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/util/executor_utils.py", line 64, in run_with_context
    return ctx.run(partial(func, *args, **kwargs))
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/scene/chat_factory.py", line 36, in get_implementation
    implementation = cls(**kwargs)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/scene/chat_db/auto_execute/chat.py", line 34, in __init__
    raise ValueError(
ValueError: <bound method ChatScene.value of <ChatScene.ChatWithDbExecute: <dbgpt.app.scene.base.Scene object at 0x7d3858dbd660>>> mode should chose db!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/home/priyamshah/.local/lib/python3.10/site-packages/coloredlogs/__init__.py", line 1140, in format
    return logging.Formatter.format(self, record)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 678, in format
    record.message = record.getMessage()
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/logging/__init__.py", line 368, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/dbgpt_server.py", line 289, in <module>
    run_webserver()
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/dbgpt_server.py", line 285, in run_webserver
    run_uvicorn(param)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/dbgpt_server.py", line 245, in run_uvicorn
    uvicorn.run(
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/uvicorn/main.py", line 579, in run
    server.run()
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/uvicorn/server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/middleware/base.py", line 149, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 288, in handle
    await self.app(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 76, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
    await app(scope, receive, sender)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/starlette/routing.py", line 73, in app
    response = await f(request)
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/fastapi/routing.py", line 301, in app
    raw_response = await run_endpoint_function(
  File "/home/priyamshah/anaconda3/envs/dbgpt_env1/lib/python3.10/site-packages/fastapi/routing.py", line 212, in run_endpoint_function
    return await dependant.call(**values)
  File "/home/priyamshah/Desktop/DB-GPT/dbgpt/app/openapi/api_v1/api_v1.py", line 552, in chat_completions
    logger.exception(f"Chat Exception!{dialogue}", e)
Message: 'Chat Exception!conv_uid=\'0012343e-a909-11ef-bcc9-08bfb8168874\' user_input=\'What is the email address of the user named "Alice Smith"?\' user_name=\'001\' chat_mode=\'chat_with_db_execute\' app_code=\'chat_with_db_execute\' temperature=0.5 select_param=\'\' model_name=\'vicuna-13b-v1.5\' incremental=False sys_code=None ext_info={}'
Arguments: (ValueError('<bound method ChatScene.value of <ChatScene.ChatWithDbExecute: <dbgpt.app.scene.base.Scene object at 0x7d3858dbd660>>> mode should chose db!'),)
INFO:     127.0.0.1:57336 - "POST /api/v1/chat/completions HTTP/1.1" 200 OK```


@Aries-ckt
Copy link
Collaborator

@priyamshah112 ,

ValueError: <bound method ChatScene.value of <ChatScene.ChatWithDbExecute: <dbgpt.app.scene.base.Scene object at 0x7d3858dbd660>>> mode should chose db!

it looks like you haven't chose your db.

Copy link
Collaborator

@csunny csunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

@csunny csunny merged commit af2d042 into eosphoros-ai:main Dec 3, 2024
6 checks passed
@w371803361
Copy link

image
根据您的建议对out_parser.py和prompt.py代码进行了修改,但是仍然如图所示输出通用的回答,请问还能如何改进?

@w371803361
Copy link

a9559b8cd398df46b3d5c29f9b0501e
348a4c02e25e2e0c4a613e0e963db53
d19c86e46dec4f94244d18b51826bfc
我遇到了上述问题,后台的direct response是我想要得到的答案,但是前端输出如图一无数据,请问能否帮我解答一下

@duguwo
Copy link

duguwo commented Jan 22, 2025

最新版本我看已经对out_parser.py和prompt.py代码进行了修改,但这个问题依然存在呢,大家怎么解决的?

@GITHUBear
Copy link
Contributor Author

image 根据您的建议对out_parser.py和prompt.py代码进行了修改,但是仍然如图所示输出通用的回答,请问还能如何改进?

能否看下是否有{ "thoughts": ..., "direct_response":..., "sql":...., "display_type":.... } 这样的JSON格式输出?

@GITHUBear
Copy link
Contributor Author

a9559b8cd398df46b3d5c29f9b0501e 348a4c02e25e2e0c4a613e0e963db53 d19c86e46dec4f94244d18b51826bfc 我遇到了上述问题,后台的direct response是我想要得到的答案,但是前端输出如图一无数据,请问能否帮我解答一下

本issue修复的是在sql无法成功生成的情况下,使用模型的response进行回复。你的问题的原因是已经生成了sql,而这个sql的执行结果是空结果

@w371803361
Copy link

看下是否有{ “thoughts”: ..., “direct_response”:..., “sql”:...., “display_type”:.... } 这样的J

后台显示有

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants