Using chatGLM3-6b, the output result of create_sql_query_chain is incorrect. #17003
Replies: 2 comments
-
🤖 Hey @CharlieZZss! Great to see you diving into the depths of LangChain again. How's the coding journey treating you this time? Based on your request, it seems you want the To achieve this, you can modify the Here's how you can modify the function: def create_sql_query_chain(
llm: BaseLanguageModel,
db: SQLDatabase,
prompt: Optional[BasePromptTemplate] = None,
k: int = 5,
) -> Runnable[Union[SQLInput, SQLInputWithTables, Dict[str, Any]], str]:
...
return (
RunnablePassthrough.assign(**inputs) # type: ignore
| (
lambda x: {
k: v
for k, v in x.items()
if k not in ("question", "table_names_to_use")
}
)
| prompt_to_use.partial(top_k=str(k))
| llm.bind(stop=["\nSQLQuery:"]) # Change this line
| StrOutputParser()
| _strip
) In the original function, the line Please note that this modification will only affect the output of the You can find the original function in the libs/langchain/langchain/chains/sql_database/query.py file in the LangChain repository. I hope this helps! If you have any other questions or need further clarification, feel free to ask. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
Hi i'm having the same issue and i cant modify create_sql_query_chain? shouldn't this already be handled |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
The issue originates from the documentation : https://python.langchain.com/docs/use_cases/sql/quickstart
When using ChatGLM3-6 as LLM, the query results generated by "create_sql_query_chain" are not in the format similar to the SQL statement "SELECT COUNT() FROM students," but rather in the format "'sql\nSELECT COUNT() FROM students;\n\nSQLResult: 3\nAnswer: 3'." How can this issue be resolved?I hope the result of its execution is an SQL Query.
I followed the tutorial to deploy the chatGLM3-6b model locally and customized an LLM class to integrate ChatGLM into the LangChain framework.https://github.com/datawhalechina/self-llm/blob/master/ChatGLM/05-ChatGLM3-6B%E6%8E%A5%E5%85%A5LangChain%E6%90%AD%E5%BB%BA%E7%9F%A5%E8%AF%86%E5%BA%93%E5%8A%A9%E6%89%8B.md
System Info
PyTorch 2.0.0
Python 3.8(ubuntu20.04)
pip install langchain==0.0.292
Beta Was this translation helpful? Give feedback.
All reactions