Spaces:
Sleeping
Sleeping
convert resposne to json (#3)
Browse files- add method to convert response into json (e9a99b2d99adf546e08017baa95626e9c9f506fa)
Co-authored-by: Michael Semren <MSemren@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -8,6 +8,7 @@ from langchain.sql_database import SQLDatabase
|
|
| 8 |
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
|
| 9 |
from langchain.agents import create_sql_agent
|
| 10 |
from langchain import OpenAI
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def tables_from_db():
|
|
@@ -50,6 +51,17 @@ def from_gpt(query: str):
|
|
| 50 |
# Run the query using the agent executor
|
| 51 |
return agent_executor.run(query)
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
def parse_into_chart(response: str):
|
| 54 |
if ":" not in response:
|
| 55 |
return response
|
|
|
|
| 8 |
from langchain.agents.agent_toolkits import SQLDatabaseToolkit
|
| 9 |
from langchain.agents import create_sql_agent
|
| 10 |
from langchain import OpenAI
|
| 11 |
+
from langchain import PromptTemplate, OpenAI, LLMChain
|
| 12 |
|
| 13 |
|
| 14 |
def tables_from_db():
|
|
|
|
| 51 |
# Run the query using the agent executor
|
| 52 |
return agent_executor.run(query)
|
| 53 |
|
| 54 |
+
def parse_into_json(result: str):
|
| 55 |
+
prompt_template = "Reformat this {result} in JSON format"
|
| 56 |
+
llm=OpenAI(temperature=0)
|
| 57 |
+
llm_chain = LLMChain(
|
| 58 |
+
llm=llm,
|
| 59 |
+
prompt=PromptTemplate.from_template(prompt_template)
|
| 60 |
+
)
|
| 61 |
+
Final_Results=llm_chain(result)
|
| 62 |
+
|
| 63 |
+
Final_Results['text']
|
| 64 |
+
|
| 65 |
def parse_into_chart(response: str):
|
| 66 |
if ":" not in response:
|
| 67 |
return response
|