Open yukiman76 opened 2 weeks ago
@yukiman76 hmm, I think you could use a partial, but I also think a partial would break the schema parsing for the function
Probably, the fn_component needs a dedicated partials dict 🤔
I was thinking the same, and FnComponent derives from QueryComponent which does have an internal partial support I can do the following temp
def parse_sql_guard_component(response: ChatResponse, test_engine: Engine) -> str:
"""Parse response to SQL."""
# simple clean SQL
sSQL = response.text.split('\n')[0].strip().strip("```").strip().replace('"', "'")
# connect to a Read Only test DB that cannot be harmed
with test_engine.connect() as connection:
try:
connection.execute(text(sSQL))
connection.commit() # commits "some statement"
except Exception as e:
raise SQLGuardError("Unsafe SQL attempt", [e.message])
return sSQL
logging.info("Initiating sql_guard_component")
sql_guard_component = FnComponent(fn=parse_sql_guard_component,
req_params={"response", "test_engine"})
sql_guard_component.partial(test_engine=test_engine)
testing now
Looks like that's working, we should think of a better solution tho, add it to the FnComponent class and make it a first class
Question Validation
Question
I would like to pass in a connection to a Function Component like the following