Update SQL templates (#12464)

This commit is contained in:
Lance Martin
2023-10-27 16:34:37 -07:00
committed by GitHub
parent a476147189
commit f10c17c6a4
14 changed files with 204 additions and 28 deletions

View File

@@ -1,3 +1,3 @@
from llamacpp.chain import chain
from sql_llamacpp.chain import chain
__all__ = ["chain"]

View File

@@ -6,6 +6,7 @@ import requests
from langchain.llms import LlamaCpp
from langchain.memory import ConversationBufferMemory
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain.pydantic_v1 import BaseModel
from langchain.schema.output_parser import StrOutputParser
from langchain.schema.runnable import RunnableLambda, RunnablePassthrough
from langchain.utilities import SQLDatabase
@@ -113,9 +114,12 @@ prompt_response = ChatPromptTemplate.from_messages(
("human", template),
]
)
# Supply the input types to the prompt
class InputType(BaseModel):
question: str
chain = (
RunnablePassthrough.assign(query=sql_response_memory)
RunnablePassthrough.assign(query=sql_response_memory).with_types(input_type=InputType)
| RunnablePassthrough.assign(
schema=get_schema,
response=lambda x: db.run(x["query"]),