Skip to content

Commit

Permalink
Adding DDD features
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchatmangpt committed Apr 13, 2024
1 parent 1dccc85 commit ec10e53
Show file tree
Hide file tree
Showing 40 changed files with 377 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry] # https://python-poetry.org/docs/pyproject/
name = "dspygen"
version = "2024.4.10.2"
version = "2024.4.11"
description = "A Ruby on Rails style framework for the DSPy (Demonstrate, Search, Predict) project for Language Models like GPT, BERT, and LLama."
authors = ["Sean Chatman <[email protected]>"]
readme = "README.md"
Expand Down
98 changes: 98 additions & 0 deletions src/dspygen/4www.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# pep8_python_source_code.py

class KeywordDiscovery:
"""AI-powered keyword discovery module."""
def __init__(self, data_source):
self.data_source = data_source

def discover_keywords(self):
"""Generate a list of potential profitable keywords."""
pass

class ContentGenerator:
"""Content generation system using AI."""
def __init__(self):
pass

def generate_content(self, keywords):
"""Generate ad content optimized for click-through rates and conversions."""
pass

class CampaignManager:
"""Manage and track PPC campaigns."""
def __init__(self):
pass

def create_campaign(self, content):
"""Set up and track PPC campaigns."""
pass

def monitor_performance(self):
"""Monitor and optimize campaign performance."""
pass

class FinancialManager:
"""Handle revenue tracking and automate revenue deposits."""
def __init__(self, bank_account):
self.bank_account = bank_account

def track_revenue(self):
"""Monitor revenue generated."""
pass

def deposit_revenue(self):
"""Automate revenue deposits."""
pass

class Dashboard:
"""User-friendly dashboard for real-time insights."""
def __init__(self, campaign_manager, financial_manager):
self.campaign_manager = campaign_manager
self.financial_manager = financial_manager

def display_insights(self):
"""Display real-time insights."""
pass

def main():
# Initialize required components
data_source = "ExampleDataSource"
bank_account = "123456789"
revenue_system = RevenueGenerationSystem(data_source, bank_account)
revenue_system.start()

class RevenueGenerationSystem:
"""Main revenue generation system."""
def __init__(self, data_source, bank_account):
self.data_source = data_source
self.bank_account = bank_account
self.keywords = None
self.content = None
self.campaign = None

def discover_keywords(self):
"""Discover keywords for the AI-powered keyword discovery."""
self.keywords = KeywordDiscovery(self.data_source).discover_keywords()

def generate_content(self):
"""Generate content for the AI-powered content generator."""
self.content = ContentGenerator().generate_content(self.keywords)

def create_campaign(self):
"""Create a campaign for the campaign manager."""
self.campaign = CampaignManager().create_campaign(self.content)

def monitor_performance(self):
"""Monitor performance using the campaign manager and dashboard."""
CampaignManager().monitor_performance(self.campaign)
Dashboard(CampaignManager(), FinancialManager(self.bank_account)).display_insights()

def start(self):
"""Start the revenue generation system."""
self.discover_keywords()
self.generate_content()
self.create_campaign()
self.monitor_performance()

if __name__ == "__main__":
main()
20 changes: 19 additions & 1 deletion src/dspygen/experiments/bkgn/get_soc_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_files_from_directory(directory, gitignore=None):
directory (str): The path to the directory.
gitignore (str, optional): The path to a .gitignore file. Defaults to None.
"""
retriever = PythonCodeRetriever(include_signatures=True, include_docstrings=True, include_executable_code=False)
retriever = PythonCodeRetriever(include_signatures=True, include_docstrings=True, include_executable_code=True)
result = retriever.forward(directory)
return result # Return the list of file contents

Expand Down Expand Up @@ -165,7 +165,25 @@ def get_services():
return get_files_from_directory('/Users/candacechatman/dev/soc/src/soc/services')


def get_modules():
"""Retrieves code snippets from the '/Users/candacechatman/dev/soc/src/soc/services' directory."""
return get_files_from_directory('/Users/candacechatman/dev/soc/src/soc/modules')


def main():
import pyperclip
pyperclip.copy(f"{get_modules()}")

def main3():
print(get_domain_models())
print(get_root_aggregates())
print(get_value_objects())

import pyperclip
pyperclip.copy(f"{get_domain_models()} {get_root_aggregates()} {get_value_objects()}")


def main2():
from loguru import logger
import os
from dspygen.utils.dspy_tools import init_dspy
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
41 changes: 41 additions & 0 deletions src/dspygen/experiments/touch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# Define the base directory for the POC
baseDir="tagee"

# Create the directory structure
mkdir -p "$baseDir"/{docs,src/{core,ui/modules,ui/data,ui/utils},tests/{unit,integration},assets/{images,sounds},lib,scripts,config}

# Create documentation files
touch "$baseDir"/docs/{GettingStarted.md,CurriculumAlignment.md,TechnicalOverview.md}

# Create source files
# Core engine files
touch "$baseDir"/src/core/{game_engine.py,narrative_engine.py,education_module.py}

# UI component files
touch "$baseDir"/src/ui/modules/{story_view.py,quiz_view.py,chatbot_view.py}
touch "$baseDir"/src/ui/data/{story_data.py,quiz_data.py,chatbot_data.py}
touch "$baseDir"/src/ui/utils/{ui_helpers.py,formatting_tools.py}

# Test files
touch "$baseDir"/tests/unit/{game_engine_test.py,narrative_engine_test.py,education_module_test.py}
touch "$baseDir"/tests/integration/{story_integration_test.py,quiz_integration_test.py,chatbot_integration_test.py}

# Asset placeholders
touch "$baseDir"/assets/images/.keep
touch "$baseDir"/assets/sounds/.keep

# Library placeholder
touch "$baseDir"/lib/.keep

# Script files
touch "$baseDir"/scripts/{setup.sh,deploy.sh,maintenance.sh}

# Configuration files
touch "$baseDir"/config/{dev.json,prod.json,test.json}

# Root files
touch "$baseDir"/{README.md,LICENSE,.gitignore}

echo "TAG-EE POC directory and file structure created."
Empty file.
90 changes: 90 additions & 0 deletions src/dspygen/modules/exam_point_weight_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
"""
import dspy
from dspygen.utils.dspy_tools import init_dspy


class ExamPointWeightModule(dspy.Module):
"""ExamPointWeightModule"""

def __init__(self, **forward_args):
super().__init__()
self.forward_args = forward_args
self.output = None

def __or__(self, other):
if other.output is None and self.output is None:
self.forward(**self.forward_args)

other.pipe(self.output)

return other

def forward(self, student_question):
pred = dspy.Predict("student_question -> exam_score")
self.output = pred(student_question=student_question).exam_score
return self.output

def pipe(self, input_str):
raise NotImplementedError("Please implement the pipe method for DSL support.")
# Replace TODO with a keyword from you forward method
# return self.forward(TODO=input_str)


from typer import Typer
app = Typer()


@app.command()
def call(student_question):
"""ExamPointWeightModule"""
init_dspy()

print(exam_point_weight_call(student_question=student_question))



def exam_point_weight_call(student_question):
exam_point_weight = ExamPointWeightModule()
return exam_point_weight.forward(student_question=student_question)



def main():
init_dspy()
student_question = ""
print(exam_point_weight_call(student_question=student_question))



from fastapi import APIRouter
router = APIRouter()

@router.post("/exam_point_weight/")
async def exam_point_weight_route(data: dict):
# Your code generation logic here
init_dspy()

print(data)
return exam_point_weight_call(**data)



"""
import streamlit as st
# Streamlit form and display
st.title("ExamPointWeightModule Generator")
student_question = st.text_input("Enter student_question")
if st.button("Submit ExamPointWeightModule"):
init_dspy()
result = exam_point_weight_call(student_question=student_question)
st.write(result)
"""

if __name__ == "__main__":
main()
89 changes: 89 additions & 0 deletions src/dspygen/rdddy/base_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import json
from pathlib import Path
from typing import TypeVar, Generic, Type, List, Optional

from pydantic import BaseModel

T = TypeVar('T', bound=BaseModel)


class BaseRepository(Generic[T]):
def __init__(self, model: Type[T], storage_file: Path):
self.model = model
self.storage_file = storage_file
self.storage_file.touch(exist_ok=True) # Ensure file exists

def _read_data(self) -> List[T]:
"""Reads and returns all model instances from the storage file."""
try:
with self.storage_file.open('r', encoding='utf-8') as file:
data = json.load(file)
return [self.model.parse_obj(item) for item in data]
except (json.JSONDecodeError, FileNotFoundError):
return []

def _write_data(self, data: List[T]) -> None:
"""Writes the provided list of model instances to the storage file."""
with self.storage_file.open('w', encoding='utf-8') as file:
json.dump([item.dict() for item in data], file, indent=4)

def add(self, item: T) -> None:
"""Adds a new model instance to the storage."""
items = self._read_data()
items.append(item)
self._write_data(items)

def get(self, **criteria) -> Optional[T]:
"""Retrieves a single model instance that matches the provided criteria."""
items = self._read_data()
for item in items:
if all(getattr(item, field) == value for field, value in criteria.items()):
return item
return None

def remove(self, **criteria) -> bool:
"""Removes model instances that match the provided criteria."""
items = self._read_data()
items_before = len(items)
items = [item for item in items if not all(getattr(item, field) == value for field, value in criteria.items())]
self._write_data(items)
return len(items) < items_before

def update(self, item: T) -> None:
"""Updates a model instance in the storage."""
items = self._read_data()
for i, existing_item in enumerate(items):
if existing_item.id == item.id: # Assuming each model has a unique 'id' field
items[i] = item
break
self._write_data(items)

def save(self, item: T) -> None:
"""Updates a model instance if it exists, otherwise inserts it."""
items = self._read_data()
for i, existing_item in enumerate(items):
if existing_item.id == item.id: # Assuming each model has a unique 'id' field
items[i] = item
self._write_data(items)
return
self.add(item)

def list_all(self) -> List[T]:
"""Returns a list of all model instances."""
return self._read_data()


def main():
"""Main function"""
# Conversation Learnng Through Dialog Repository

class ConversationRepository(BaseRepository[Conversation]):
def __init__(self, storage_file: Path):
super().__init__(Conversation, storage_file)


if __name__ == '__main__':
main()



5 changes: 2 additions & 3 deletions src/dspygen/rm/chatgpt_chromadb_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# Configure loguru logger
logger.add("chatgpt_chromadb_retriever.log", rotation="10 MB", level="ERROR")


def calculate_file_checksum(file_path: str) -> str:
hash_md5 = hashlib.md5()
with open(file_path, "rb") as f:
Expand Down Expand Up @@ -83,8 +84,6 @@ def __init__(self,
logger.info("Detected changes in the conversation history, processing...")
self._process_and_store_conversations()
self._save_last_processed_checksum()
# else:
# logger.info("No changes detected in the conversation history. Skipping processing.")

def _load_last_processed_checksum(self) -> Optional[str]:
checksum_file = self.persist_directory / "last_checksum.txt"
Expand Down Expand Up @@ -195,7 +194,7 @@ def main():
init_dspy(lm_class=Groq, model="mixtral-8x7b-32768")

retriever = ChatGPTChromaDBRetriever()
query = "DSPyGen Retriever to generate a ProjectStructureRetriever"
query = "Revenue Operations Automation"
matched_conversations = retriever.forward(query, k=10)
# print(count_tokens(str(matched_conversations) + "\nI want a DSPy module that generates Python source code."))
for conversation in matched_conversations:
Expand Down
Loading

0 comments on commit ec10e53

Please sign in to comment.