from langchaincommunity.utilities import SQLDatabase from langchain import…
Private research annotation
Sign in to add a private research label or note.
- User
from langchain_community.utilities import SQLDatabase from langchain import PromptTemplate from langchain_experimental.sql import SQLDatabaseChain from langchain_experimental.chat_models import Llama2Chat from langchain.llms import LlamaCpp from dotenv import load_dotenv import os import sqlglot from langchain.chains import LLMChain class SQLQueryGenerator: def init(self): self.load_env_variables() self.setup_database() self.setup_llm() def load_env_variables(self): load_dotenv() self.db_uri = os.getenv('DB_CONNECTION_STRING') self.model_path = os.getenv('MODEL_PATH') self.temperature = float(os.getenv('TEMPERATURE')) self.max_tokens = int(os.getenv('MAX_TOKENS')) self.top_p = float(os.getenv('TOP_P')) self.n_ctx = int(os.getenv('N_CTX')) self.table_names = os.getenv('TABLES_NAME').split(',') self.second_model_path = os.getenv('SECOND_MODEL_PATH')
def setup_database(self): self.db = SQLDatabase.from_uri(self.db_uri, include_tables=self.table_names, view_support=True) print(self.db.dialect)
def setup_llm(self): self.llm = LlamaCpp( model_path=self.model_path, temperature=self.temperature, max_tokens=self.max_tokens, top_p=self.top_p, verbose=True, n_ctx=self.n_ctx )
def create_template(self, question): return f"""### Instructions: Your task is to convert a question into a SQL query, given a MySQL database schema. Adhere to these rules: - Deliberately go through the question and database schema word by word to appropriately answer the question - **Strictly Do not use 'ilike' instead use 'like' for the queries where it is required - We have a MySQL database so generate the query as per MySQL syntax only not as per other SQL databases like Postgres, Oracle, and other SQL databases. - Use Table Aliases to prevent ambiguity. For example,
SELECT table1.col1, table2.col1 FROM table1 JOIN table2 ON table1.id = table2.id. - When creating a ratio, always cast the numerator as float - **Also make sure that generated query is syntactically correct and will produce correct results on execution.code - Assistant
- User
load_dotenv() self.db_uri = os.getenv(‘DB_CONNECTION_STRING’) self.model_path = os.getenv(‘MODEL_PATH’) self.temperature = float(os.getenv(‘TEMPERATURE’)) self.max_tokens = int(os.getenv(‘MAX_TOKENS’)) self.top_p = float(os.getenv(‘TOP_P’)) self.n_ctx = int(os.getenv(‘N_CTX’)) self.table_names = os.getenv(‘TABLES_NAME’).split(‘,’) self.second_model_path = os.getenv(‘SECOND_MODEL_PATH’)
i wnat to give all things hardcoded here in the code
- Assistant
- User
× Building wheel for llama-cpp-python (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [24 lines of output] *** scikit-build-core 0.9.5 using CMake 3.29.3 (wheel) *** Configuring CMake... loading initial cache file /tmp/tmpgua8g8pz/build/CMakeInit.txt -- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:3 (project): No CMAKE_C_COMPILER could be found.
codeTell CMake where to find the compiler by setting either the environment variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. CMake Error at CMakeLists.txt:3 (project): No CMAKE_CXX_COMPILER could be found. Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. -- Configuring incomplete, errors occurred! *** CMake configuration failed [end of output] - Assistant
The error you're encountering indicates that the C compiler and C++ compiler required by CMake are not present on your system or are not correctly configured in the PATH. This is preventing the
llama-cpp-pythonpackage from being built.To resolve this, you'll need to install the necessary build tools and compilers. Here's how you can do it on various operating systems:
On Ubuntu/Debian:
You need to install the build-essential package, which includes the GCC compiler and other necessary build tools.