Fer-geo commited on
Commit
7182eb1
·
1 Parent(s): 2da7871
.devcontainer/devcontainer.json CHANGED
@@ -42,5 +42,9 @@
42
  // "ghcr.io/devcontainers-contrib/features/coverage-py:2": {},
43
  // "git": "latest",
44
  // "github-cli": "latest"
45
- }
 
 
 
 
46
  }
 
42
  // "ghcr.io/devcontainers-contrib/features/coverage-py:2": {},
43
  // "git": "latest",
44
  // "github-cli": "latest"
45
+ },
46
+ // add environment variables
47
+ "containerEnv": {
48
+ "OPENAI_API_KEY": "${localEnv:OPENAI_API_KEY}"
49
+ }
50
  }
streamlit_agent/Untitled-1.ipynb ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "ename": "OperationalError",
10
+ "evalue": "unable to open database file",
11
+ "output_type": "error",
12
+ "traceback": [
13
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
14
+ "\u001b[1;31mOperationalError\u001b[0m Traceback (most recent call last)",
15
+ "Cell \u001b[1;32mIn[2], line 4\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mpandas\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39mpd\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39msqlite3\u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m conn \u001b[39m=\u001b[39m sqlite3\u001b[39m.\u001b[39;49mconnect(\u001b[39m'\u001b[39;49m\u001b[39mstreamlit_agent\u001b[39;49m\u001b[39m\\\u001b[39;49m\u001b[39msitios2.sqlite\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[0;32m 5\u001b[0m df \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mread_sql_query(\u001b[39m\"\u001b[39m\u001b[39mSELECT * FROM sitiospilotojson\u001b[39m\u001b[39m\"\u001b[39m, conn)\n\u001b[0;32m 6\u001b[0m conn\u001b[39m.\u001b[39mclose()\n",
16
+ "\u001b[1;31mOperationalError\u001b[0m: unable to open database file"
17
+ ]
18
+ }
19
+ ],
20
+ "source": [
21
+ "import pandas as pd\n",
22
+ "import sqlite3\n",
23
+ "\n",
24
+ "conn = sqlite3.connect('streamlit_agent\\sitios2.sqlite')\n",
25
+ "df = pd.read_sql_query(\"SELECT * FROM sitiospilotojson\", conn)\n",
26
+ "conn.close()\n",
27
+ "\n",
28
+ "df"
29
+ ]
30
+ }
31
+ ],
32
+ "metadata": {
33
+ "kernelspec": {
34
+ "display_name": "Python 3",
35
+ "language": "python",
36
+ "name": "python3"
37
+ },
38
+ "language_info": {
39
+ "codemirror_mode": {
40
+ "name": "ipython",
41
+ "version": 3
42
+ },
43
+ "file_extension": ".py",
44
+ "mimetype": "text/x-python",
45
+ "name": "python",
46
+ "nbconvert_exporter": "python",
47
+ "pygments_lexer": "ipython3",
48
+ "version": "3.11.4"
49
+ },
50
+ "orig_nbformat": 4
51
+ },
52
+ "nbformat": 4,
53
+ "nbformat_minor": 2
54
+ }
streamlit_agent/mrkl_demo.py CHANGED
@@ -12,26 +12,28 @@ from langchain.utilities import DuckDuckGoSearchAPIWrapper
12
 
13
  from streamlit_agent.callbacks.capturing_callback_handler import playback_callbacks
14
  from streamlit_agent.clear_results import with_clear_container
 
15
 
16
- DB_PATH = (Path(__file__).parent / "Chinook.db").absolute()
 
 
 
17
 
18
  SAVED_SESSIONS = {
19
- "Who is Leo DiCaprio's girlfriend? What is her current age raised to the 0.43 power?": "leo.pickle",
20
- "What is the full name of the artist who recently released an album called "
21
- "'The Storm Before the Calm' and are they in the FooBar database? If so, what albums of theirs "
22
- "are in the FooBar database?": "alanis.pickle",
23
  }
24
 
25
  st.set_page_config(
26
  page_title="MRKL", page_icon="🦜", layout="wide", initial_sidebar_state="collapsed"
27
  )
28
 
29
- "# 🦜🔗 MRKL"
30
 
31
  # Setup credentials in Streamlit
32
- user_openai_api_key = st.sidebar.text_input(
33
- "OpenAI API Key", type="password", help="Set this to run your own custom questions."
34
- )
35
 
36
  if user_openai_api_key:
37
  openai_api_key = user_openai_api_key
@@ -58,9 +60,9 @@ tools = [
58
  description="useful for when you need to answer questions about math",
59
  ),
60
  Tool(
61
- name="FooBar DB",
62
  func=db_chain.run,
63
- description="useful for when you need to answer questions about FooBar. Input should be in the form of a question containing full context",
64
  ),
65
  ]
66
 
@@ -69,6 +71,18 @@ mrkl = initialize_agent(
69
  tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
70
  )
71
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  with st.form(key="form"):
73
  if not enable_custom:
74
  "Ask one of the sample questions, or enter your API Key in the sidebar to ask your own custom questions."
@@ -77,7 +91,7 @@ with st.form(key="form"):
77
 
78
  if enable_custom:
79
  user_input = st.text_input("Or, ask your own question")
80
- if not mrkl_input:
81
  user_input = prefilled
82
  submit_clicked = st.form_submit_button("Submit Question")
83
 
@@ -91,12 +105,12 @@ if with_clear_container(submit_clicked):
91
 
92
  # If we've saved this question, play it back instead of actually running LangChain
93
  # (so that we don't exhaust our API calls unnecessarily)
94
- if user_input in SAVED_SESSIONS:
95
- session_name = SAVED_SESSIONS[user_input]
96
- session_path = Path(__file__).parent / "runs" / session_name
97
- print(f"Playing saved session: {session_path}")
98
- answer = playback_callbacks([st_callback], str(session_path), max_pause_time=2)
99
- else:
100
- answer = mrkl.run(user_input, callbacks=[st_callback])
101
-
102
  answer_container.write(answer)
 
12
 
13
  from streamlit_agent.callbacks.capturing_callback_handler import playback_callbacks
14
  from streamlit_agent.clear_results import with_clear_container
15
+ import os
16
 
17
+ user_openai_api_key = os.environ.get('OPENAI_API_KEY')
18
+
19
+ # DB_PATH = (Path(__file__).parent / "Chinook.db").absolute()
20
+ DB_PATH = (Path(__file__).parent / "sitios2.sqlite").absolute()
21
 
22
  SAVED_SESSIONS = {
23
+ "Que provincias están representadas en los sitios pilotos?": "alanis.pickle",
24
+ "Cual es la superficie total de sitios piloto en Buenos Aires?": "alanis.pickle",
 
 
25
  }
26
 
27
  st.set_page_config(
28
  page_title="MRKL", page_icon="🦜", layout="wide", initial_sidebar_state="collapsed"
29
  )
30
 
31
+ "# Tabla Sitios Piloto"
32
 
33
  # Setup credentials in Streamlit
34
+ # user_openai_api_key = st.sidebar.text_input(
35
+ # "OpenAI API Key", type="password", help="Set this to run your own custom questions."
36
+ # )
37
 
38
  if user_openai_api_key:
39
  openai_api_key = user_openai_api_key
 
60
  description="useful for when you need to answer questions about math",
61
  ),
62
  Tool(
63
+ name="sitios piloto DB",
64
  func=db_chain.run,
65
+ description="useful for when you need to answer questions about sitios piloto. Input should be in the form of a question containing full context",
66
  ),
67
  ]
68
 
 
71
  tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
72
  )
73
 
74
+ # read sitios2.sqlite and convert it to dataframe
75
+
76
+ import pandas as pd
77
+ import sqlite3
78
+
79
+ conn = sqlite3.connect(DB_PATH)
80
+ df = pd.read_sql_query("SELECT spoat, ecorregion, sag, provincia, supha, area, departamento FROM sitiospilotojson", conn)
81
+ conn.close()
82
+
83
+ st.write(df)
84
+
85
+
86
  with st.form(key="form"):
87
  if not enable_custom:
88
  "Ask one of the sample questions, or enter your API Key in the sidebar to ask your own custom questions."
 
91
 
92
  if enable_custom:
93
  user_input = st.text_input("Or, ask your own question")
94
+ if not user_input:
95
  user_input = prefilled
96
  submit_clicked = st.form_submit_button("Submit Question")
97
 
 
105
 
106
  # If we've saved this question, play it back instead of actually running LangChain
107
  # (so that we don't exhaust our API calls unnecessarily)
108
+ # if user_input in SAVED_SESSIONS:
109
+ # session_name = SAVED_SESSIONS[user_input]
110
+ # session_path = Path(__file__).parent / "runs" / session_name
111
+ # print(f"Playing saved session: {session_path}")
112
+ # answer = playback_callbacks([st_callback], str(session_path), max_pause_time=2)
113
+ # else:
114
+ # answer = mrkl.run(user_input, callbacks=[st_callback])
115
+ answer = mrkl.run(user_input, callbacks=[st_callback])
116
  answer_container.write(answer)
streamlit_agent/runs/alanis copy.p ADDED
Binary file (60.7 kB). View file
 
streamlit_agent/runs/alanis.bak ADDED
File without changes
streamlit_agent/runs/alanis.dat ADDED
File without changes
streamlit_agent/runs/alanis.dir ADDED
File without changes