-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyautomator starting to get off the ground.
- Loading branch information
1 parent
1250b44
commit a82bd59
Showing
67 changed files
with
3,350 additions
and
421 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
"""Streamlit app.""" | ||
|
||
from importlib.metadata import version | ||
|
||
import streamlit as st | ||
|
||
from dspygen.modules.chat_bot_module import chat_bot_call | ||
from dspygen.modules.insight_tweet_module import insight_tweet_call | ||
from dspygen.modules.streamlit_bot_module import streamlit_bot_call | ||
from dspygen.utils.dspy_tools import init_dspy | ||
from dspygen.utils.file_tools import source_dir, pages_dir | ||
|
||
st.title(f"dspygen v{version('dspygen')}") # type: ignore[no-untyped-call] | ||
|
||
|
||
# # Streamlit form and display | ||
# st.title("Insight Tweet Generator") | ||
# | ||
# insight_input = st.text_input("Enter your insight:") | ||
# | ||
# if st.button("Generate Tweet"): | ||
# init_dspy() | ||
# result = insight_tweet_call(insight_input) | ||
# st.write(result) | ||
|
||
from st_pages import Page, show_pages, add_page_title | ||
|
||
# Optional -- adds the title and icon to the current page | ||
add_page_title() | ||
|
||
# Specify what pages should be shown in the sidebar, and what their titles and icons | ||
# should be | ||
|
||
page_list = [Page(str(source_dir("app.py")), "Home", "🏠")] | ||
|
||
# loop through the pages and display them | ||
for page_src in pages_dir().iterdir(): | ||
if page_src.is_file() and page_src.suffix == ".py": | ||
page_list.append(Page(str(page_src), page_src.stem, ":books:")) | ||
|
||
# Remove __init__.py from the list | ||
page_list = [page for page in page_list if page.name != "init"] | ||
|
||
# show_pages(page_list) | ||
# """Streamlit app.""" | ||
# | ||
# from importlib.metadata import version | ||
# | ||
# import streamlit as st | ||
# | ||
# from dspygen.modules.chat_bot_module import chat_bot_call | ||
# from dspygen.modules.insight_tweet_module import insight_tweet_call | ||
# from dspygen.modules.streamlit_bot_module import streamlit_bot_call | ||
# from dspygen.utils.dspy_tools import init_dspy | ||
# from dspygen.utils.file_tools import source_dir, pages_dir | ||
# | ||
# st.title(f"dspygen v{version('dspygen')}") # type: ignore[no-untyped-call] | ||
# | ||
# | ||
# # # Streamlit form and display | ||
# # st.title("Insight Tweet Generator") | ||
# # | ||
# # insight_input = st.text_input("Enter your insight:") | ||
# # | ||
# # if st.button("Generate Tweet"): | ||
# # init_dspy() | ||
# # result = insight_tweet_call(insight_input) | ||
# # st.write(result) | ||
# | ||
# from st_pages import Page, show_pages, add_page_title | ||
# | ||
# # Optional -- adds the title and icon to the current page | ||
# add_page_title() | ||
# | ||
# # Specify what pages should be shown in the sidebar, and what their titles and icons | ||
# # should be | ||
# | ||
# page_list = [Page(str(source_dir("app.py")), "Home", "🏠")] | ||
# | ||
# # loop through the pages and display them | ||
# for page_src in pages_dir().iterdir(): | ||
# if page_src.is_file() and page_src.suffix == ".py": | ||
# page_list.append(Page(str(page_src), page_src.stem, ":books:")) | ||
# | ||
# # Remove __init__.py from the list | ||
# page_list = [page for page in page_list if page.name != "init"] | ||
# | ||
# # show_pages(page_list) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import dspy | ||
from dspygen.utils.dspy_tools import init_dspy, init_ol | ||
from dspygen.rm.data_retriever import read_any | ||
from dspygen.rm.doc_retriever import read_any as doc_read_any | ||
import pandas as pd | ||
import io | ||
|
||
class AskDataSignature(dspy.Signature): | ||
""" | ||
Answers a natural language question about data from a file. | ||
""" | ||
question = dspy.InputField(desc="Natural language question about the data.") | ||
data = dspy.InputField(desc="The data content from the file.") | ||
answer = dspy.OutputField(desc="Plain text answer to the question.") | ||
|
||
class AskDataModule(dspy.Module): | ||
"""AskDataModule for answering questions about data from various file types""" | ||
|
||
def __init__(self, **forward_args): | ||
super().__init__() | ||
self.forward_args = forward_args | ||
|
||
def forward(self, question, file_path): | ||
try: | ||
# First, try to read as structured data | ||
data = read_any(file_path, query="") | ||
if isinstance(data, pd.DataFrame): | ||
csv_buffer = io.StringIO() | ||
data.to_csv(csv_buffer, index=False) | ||
data = csv_buffer.getvalue() | ||
else: | ||
data = str(data) | ||
except Exception: | ||
try: | ||
# If that fails, try to read as a document | ||
data = doc_read_any(file_path) | ||
if isinstance(data, dict): | ||
data = "\n".join(data.values()) | ||
data = str(data) | ||
except Exception: | ||
# If both fail, read as plain text | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
data = file.read() | ||
|
||
pred = dspy.Predict(AskDataSignature) | ||
return pred(question=question, data=data).answer | ||
|
||
def ask_data_call(question, file_path): | ||
ask_data_module = AskDataModule() | ||
return ask_data_module.forward(question=question, file_path=file_path) | ||
|
||
def main(): | ||
# init_ol(model="mistral-nemo") | ||
init_ol(model="qwen2:latest") | ||
# init_ol(model="mistral-nemo") | ||
# Example usage | ||
from dspygen.experiments.cal_apps.reminder_app import RemindersApp | ||
app = RemindersApp() | ||
app.export_reminders("reminders.csv") | ||
question = "Can you answer me a new appointment for a haircut at 1pm on 9/1" | ||
|
||
result = ask_data_call(question=question, file_path="reminders.csv") | ||
print(result) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import dspy | ||
from dspygen.utils.dspy_tools import init_dspy | ||
import pandas as pd | ||
import io | ||
|
||
class AskDFSignature(dspy.Signature): | ||
""" | ||
Answers a natural language question about a DataFrame. | ||
""" | ||
question = dspy.InputField(desc="Natural language question about the DataFrame.") | ||
df_csv = dspy.InputField(desc="The DataFrame in CSV string format.") | ||
answer = dspy.OutputField(desc="Plain text answer to the question.") | ||
|
||
class AskDFModule(dspy.Module): | ||
"""AskDFModule for answering questions about DataFrames using natural language""" | ||
|
||
def __init__(self, **forward_args): | ||
super().__init__() | ||
self.forward_args = forward_args | ||
|
||
def forward(self, question, df): | ||
# Convert DataFrame to CSV string | ||
csv_buffer = io.StringIO() | ||
df.to_csv(csv_buffer, index=False) | ||
df_csv = csv_buffer.getvalue() | ||
|
||
pred = dspy.Predict(AskDFSignature) | ||
return pred(question=question, df_csv=df_csv).answer | ||
|
||
def ask_df_call(question, df): | ||
ask_df_module = AskDFModule() | ||
return ask_df_module.forward(question=question, df=df) | ||
|
||
def main(): | ||
init_dspy() | ||
# Example usage | ||
df = pd.DataFrame({ | ||
'name': ['Alice', 'Bob', 'Charlie'], | ||
'age': [25, 30, 35], | ||
'city': ['New York', 'San Francisco', 'London'] | ||
}) | ||
question = "Who is older than 30?" | ||
|
||
result = ask_df_call(question=question, df=df) | ||
print(result) | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.