Skip to content

Commit

Permalink
pyautomator starting to get off the ground.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchatmangpt committed Aug 30, 2024
1 parent 1250b44 commit a82bd59
Show file tree
Hide file tree
Showing 67 changed files with 3,350 additions and 421 deletions.
30 changes: 29 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ trafilatura = "^1.12.1"
pyobjc = "^10.3.1"
pyobjc-framework-eventkit = "^10.3.1"
icalendar = "^5.0.13"
pyobjc-framework-contacts = "^10.3.1"
pytz = "^2024.1"
apscheduler = "^3.10.4"

[tool.poetry.group.test.dependencies] # https://python-poetry.org/docs/master/managing-dependencies/
coverage = { extras = ["toml"], version = ">=7.2.5" }
Expand Down
1 change: 1 addition & 0 deletions src/dspygen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ def configure_injector(binder):
event_store = EventKit.EKEventStore.alloc().init()
binder.bind(EventKit.EKEventStore, event_store)


inject.configure(configure_injector)
88 changes: 44 additions & 44 deletions src/dspygen/dspygen_app.py
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)
6 changes: 0 additions & 6 deletions src/dspygen/experiments/cal_apps/__init__.py

This file was deleted.

40 changes: 0 additions & 40 deletions src/dspygen/experiments/cal_apps/calendar_set.py

This file was deleted.

66 changes: 66 additions & 0 deletions src/dspygen/modules/ask_data_module.py
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()
48 changes: 48 additions & 0 deletions src/dspygen/modules/ask_df_module.py
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()
Loading

0 comments on commit a82bd59

Please sign in to comment.