themissingCRAM
commited on
Commit
·
7ded5fa
1
Parent(s):
d23e6f9
cleanup
Browse files
app.py
CHANGED
|
@@ -53,18 +53,7 @@ def sql_engine_tool(query: str) -> str:
|
|
| 53 |
query: The query to perform. This should be correct SQL.
|
| 54 |
"""
|
| 55 |
output = ""
|
| 56 |
-
print("debug sql_engine_tool")
|
| 57 |
-
print(engine)
|
| 58 |
with engine.begin() as con:
|
| 59 |
-
print(con.connection)
|
| 60 |
-
print(metadata_objects.tables.keys())
|
| 61 |
-
result = con.execute(
|
| 62 |
-
text(
|
| 63 |
-
"SELECT name FROM sqlite_master WHERE type='table' AND name='receipts'"
|
| 64 |
-
)
|
| 65 |
-
)
|
| 66 |
-
print("tables available:", result.fetchone())
|
| 67 |
-
|
| 68 |
rows = con.execute(text(query))
|
| 69 |
for row in rows:
|
| 70 |
output += "\n" + str(row)
|
|
@@ -72,7 +61,6 @@ def sql_engine_tool(query: str) -> str:
|
|
| 72 |
|
| 73 |
|
| 74 |
def init_db(engine):
|
| 75 |
-
|
| 76 |
metadata_obj = MetaData()
|
| 77 |
|
| 78 |
def insert_rows_into_table(rows, table, engine=engine):
|
|
@@ -109,17 +97,13 @@ def init_db(engine):
|
|
| 109 |
},
|
| 110 |
]
|
| 111 |
insert_rows_into_table(rows, receipts)
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
print("init_db debug")
|
| 115 |
-
print(engine)
|
| 116 |
-
print()
|
| 117 |
-
return engine, metadata_obj
|
| 118 |
|
| 119 |
|
| 120 |
if __name__ == "__main__":
|
| 121 |
engine = create_engine("sqlite:///:localhost:")
|
| 122 |
-
engine
|
| 123 |
model = HfApiModel(
|
| 124 |
model_id="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 125 |
token=os.getenv("my_first_agents_hf_tokens"),
|
|
@@ -131,10 +115,8 @@ if __name__ == "__main__":
|
|
| 131 |
max_steps=10,
|
| 132 |
verbosity_level=1,
|
| 133 |
)
|
| 134 |
-
# GradioUI(agent).launch()
|
| 135 |
|
| 136 |
def enter_message(new_message, conversation_history):
|
| 137 |
-
|
| 138 |
conversation_history.append(gr.ChatMessage(role="user", content=new_message))
|
| 139 |
yield "", conversation_history
|
| 140 |
for msg in stream_to_gradio(agent, new_message):
|
|
@@ -143,7 +125,7 @@ if __name__ == "__main__":
|
|
| 143 |
|
| 144 |
with gr.Blocks() as b:
|
| 145 |
chatbot = gr.Chatbot(type="messages", height=1000)
|
| 146 |
-
textbox = gr.Textbox()
|
| 147 |
button = gr.Button("reply")
|
| 148 |
button.click(enter_message, [textbox, chatbot], [textbox, chatbot])
|
| 149 |
-
b.launch(
|
|
|
|
| 53 |
query: The query to perform. This should be correct SQL.
|
| 54 |
"""
|
| 55 |
output = ""
|
|
|
|
|
|
|
| 56 |
with engine.begin() as con:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
rows = con.execute(text(query))
|
| 58 |
for row in rows:
|
| 59 |
output += "\n" + str(row)
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
def init_db(engine):
|
|
|
|
| 64 |
metadata_obj = MetaData()
|
| 65 |
|
| 66 |
def insert_rows_into_table(rows, table, engine=engine):
|
|
|
|
| 97 |
},
|
| 98 |
]
|
| 99 |
insert_rows_into_table(rows, receipts)
|
| 100 |
+
|
| 101 |
+
return engine
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|
| 105 |
engine = create_engine("sqlite:///:localhost:")
|
| 106 |
+
engine = init_db(engine)
|
| 107 |
model = HfApiModel(
|
| 108 |
model_id="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 109 |
token=os.getenv("my_first_agents_hf_tokens"),
|
|
|
|
| 115 |
max_steps=10,
|
| 116 |
verbosity_level=1,
|
| 117 |
)
|
|
|
|
| 118 |
|
| 119 |
def enter_message(new_message, conversation_history):
|
|
|
|
| 120 |
conversation_history.append(gr.ChatMessage(role="user", content=new_message))
|
| 121 |
yield "", conversation_history
|
| 122 |
for msg in stream_to_gradio(agent, new_message):
|
|
|
|
| 125 |
|
| 126 |
with gr.Blocks() as b:
|
| 127 |
chatbot = gr.Chatbot(type="messages", height=1000)
|
| 128 |
+
textbox = gr.Textbox(lines=3)
|
| 129 |
button = gr.Button("reply")
|
| 130 |
button.click(enter_message, [textbox, chatbot], [textbox, chatbot])
|
| 131 |
+
b.launch()
|