Skip to content

Commit

Permalink
Fixing library, first tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchatmangpt committed Feb 26, 2024
1 parent 31a4301 commit f5ffb5f
Show file tree
Hide file tree
Showing 33 changed files with 301 additions and 490 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
git config --global init.defaultBranch main
PYTHON_VERSION=${{ matrix.python-version }} devcontainer up --workspace-folder .
- name: Lint package
run: devcontainer exec --workspace-folder . poe lint

- name: Test package
run: devcontainer exec --workspace-folder . poe test

Expand Down
148 changes: 148 additions & 0 deletions chain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
TypedBuildCoreComponentsPrompt:
classes:
- TypedPrompt
- Chat
description: Develop core components of the DSL.
error_handling: Exception Handling
methods:
- execute
- validate
parsers:
- YAML Parser
- JSON Parser
performance_metrics:
- Speed
- Memory
source: Develop parsers {{ parsers }} for the YAML configurations. Implement classes
{{ classes }} and methods {{ methods }} for functionalities. Include {{ error_handling
}} and consider {{ performance_metrics }}.
title: Build Core Components
TypedDeploymentPrompt:
backup_plan: Daily Backups
ci_cd_pipelines:
- Jenkins
- GitLab
deployment_strategy: Blue-Green
description: Deploy the system.
monitoring_tools:
- Prometheus
- Grafana
rollback_procedures:
- Automated
- Manual
source: Choose an appropriate deployment strategy {{ deployment_strategy }}. Implement
CI/CD pipelines {{ ci_cd_pipelines }}, use monitoring tools {{ monitoring_tools
}}, have a backup plan {{ backup_plan }}, and prepare rollback procedures {{ rollback_procedures
}}.
title: Deployment
TypedDesignArchitecturePrompt:
components:
- Parser
- Executor
description: Design the DSL architecture.
interactions:
- Data Flow
- Control Flow
modularity: Modular
scalability: High
source: Plan how the DSL will interact with other system components {{ components
}}. Define the DSL's syntax {{ syntax }}, ensure {{ scalability }} and {{ modularity
}}, and outline component interactions {{ interactions }}.
syntax: YAML-based
title: Design Architecture
TypedDocumentationPrompt:
api_docs:
- Endpoints
- Examples
description: Create detailed documentation.
documentation_types:
- API
- User Guide
faqs:
- General
- Technical
source: Create detailed documentation types {{ documentation_types }} and offer
training sessions or materials to end-users including user guides {{ user_guides
}}, API documentation {{ api_docs }}, tutorials {{ tutorials }}, and FAQs {{ faqs
}}.
title: Documentation
tutorials:
- Video
- Text
user_guides:
- Getting Started
- Advanced
TypedImplementBusinessLogicPrompt:
algorithms:
- NLP
- ML
data_models:
- User
- Environment
description: Implement the business logic.
goal_setting: S.M.A.R.T
optimization_criteria:
- Efficiency
- Accuracy
source: Add logic for team composition {{ team_composition }}, goal setting {{ goal_setting
}}, use data models {{ data_models }}, apply algorithms {{ algorithms }}, and
meet optimization criteria {{ optimization_criteria }}.
team_composition: Cross-functional
title: Implement Business Logic
TypedMaintenancePrompt:
description: Maintain and update the system.
monitoring_metrics:
- CPU Usage
- Error Rate
patching_policy: Security First
source: Monitor system's usage and performance using metrics {{ monitoring_metrics
}}. Apply patches and updates as required following the update schedule {{ update_schedule
}} and patching policy {{ patching_policy }}. Provide support through channels
{{ support_channels }} and collect feedback via {{ user_feedback_mechanisms }}.
support_channels:
- Email
- Chat
title: Maintenance
update_schedule: Monthly
user_feedback_mechanisms:
- Survey
- Reviews
TypedRequirementAnalysisPrompt:
constraints:
- Time
- Budget
core_functionalities:
- Parsing
- Error Handling
description: Gather detailed requirements for the DSL.
source: Gather detailed requirements that the DSL needs to fulfill. Identify core
functionalities, consult with {{ stakeholders }}, consider {{ constraints }},
choose appropriate {{ technologies }}, within the timeframe of {{ timeframe }}.
stakeholders:
- Product Manager
- Dev Team
- QA Team
technologies:
- Python
- YAML
timeframe: Q1
title: Requirement Analysis
TypedTestingPrompt:
description: Conduct thorough testing.
integration_tests:
- test_end_to_end
source: Write unit tests {{ unit_tests }}, validate through integration tests {{
integration_tests }}, perform stress tests {{ stress_tests }}, use test data {{
test_data }} in various test environments {{ test_environments }}.
stress_tests:
- test_load
test_data:
- Sample YAML
- Sample JSON
test_environments:
- Local
- Staging
title: Testing
unit_tests:
- test_parser
- test_executor
21 changes: 20 additions & 1 deletion poetry.lock

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

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry] # https://python-poetry.org/docs/pyproject/
name = "dspygen"
version = "2024.2.25"
version = "2024.2.25.2"
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"
repository = "https://github.com/user/my-package"
repository = "https://github.com/seanchatmangpt/dspygen"

[tool.poetry.scripts] # https://python-poetry.org/docs/pyproject/#scripts
dspygen = "dspygen.cli:app"
Expand All @@ -33,6 +33,7 @@ openai = "^1.12.0"
pyperclip = "^1.8.2"
asyncer = "^0.0.5"
loguru = "^0.7.2"
groq = "^0.4.1"

[tool.poetry.group.test.dependencies] # https://python-poetry.org/docs/master/managing-dependencies/
coverage = { extras = ["toml"], version = ">=7.2.5" }
Expand Down
28 changes: 28 additions & 0 deletions src/dspygen/async_typer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import inspect
from functools import partial, wraps

import asyncer
from typer import Typer


class AsyncTyper(Typer):
@staticmethod
def maybe_run_async(decorator, f):
if inspect.iscoroutinefunction(f):

@wraps(f)
def runner(*args, **kwargs):
return asyncer.runnify(f)(*args, **kwargs)

decorator(runner)
else:
decorator(f)
return f

def callback(self, *args, **kwargs):
decorator = super().callback(*args, **kwargs)
return partial(self.maybe_run_async, decorator)

def command(self, *args, **kwargs):
decorator = super().command(*args, **kwargs)
return partial(self.maybe_run_async, decorator)
66 changes: 65 additions & 1 deletion src/dspygen/cli.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""dspygen CLI."""
from importlib import import_module

import dspy
import os

from pathlib import Path

import typer

from dspygen.utils.dspy_tools import init_dspy

app = typer.Typer()


Expand All @@ -32,7 +35,68 @@ def init(project_name: str):
typer.echo(f"Initializing {project_name}.")


README = """DSPyGen: Streamlining AI Development
DSPyGen, influenced by the efficiency and modularity of Ruby on Rails, is a powerful command-line interface (CLI) designed to revolutionize AI development by leveraging DSPy modules. This tool simplifies the process of creating, developing, and deploying language model (LM) pipelines, embodying the Ruby on Rails philosophy of "Convention over Configuration" for AI projects.
Features
Quick Initialization: Set up your DSPyGen project in seconds, echoing Ruby on Rails' ease of starting new projects.
Modular Approach: Inspired by Ruby on Rails' modular design, DSPyGen allows for the easy generation and enhancement of DSPy modules.
Intuitive Command Structure: With user-friendly commands, managing your AI development workflow becomes as straightforward as web development with Ruby on Rails.
Embedded Chatbot Assistance: For guidance and support, DSPyGen includes a chatbot, making it easier to navigate through your development process."""


@app.command("help")
def cli_help(question: str):
"""Answers the user questions with a helpful chatbot."""
typer.echo(f"TODO: Answer {question}.")
chatbot(question, README)


def gbot(question, context):
from groq import Groq

client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)

chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": f"you are a helpful assistant. This is what you help with: {context}"
},
{
"role": "user",
"content": f"{question}",
}
],
model="llama2-70b-4096",
)

print(chat_completion.choices[0].message.content.rstrip())


def chatbot(question, context, history=""):
init_dspy(max_tokens=2000)

qa = dspy.ChainOfThought("question, context -> answer")
response = qa(question=question, context=context).answer
history += response
print(f"Chatbot: {response}")
confirmed = False
while not confirmed:
confirm = typer.prompt("Did this answer your question? [y/N]", default="N")

if confirm.lower() in ["y", "yes"]:
confirmed = True
else:
want = typer.prompt("How can I help more?")

question = f"{history}\n{want}"
question = question[-1000:]

response = qa(question=question, context=README).answer
history += response
print(f"Chatbot: {response}")

return history

2 changes: 1 addition & 1 deletion src/dspygen/modules/gen_dspy_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dspygen.modules.gen_pydantic_instance_module import gen_pydantic_instance_call
from dspygen.modules.source_code_pep8_docs_module import source_code_docs_call
from dspygen.utils.dspy_tools import init_dspy
from typetemp.functional import render
from dspygen.typetemp.functional import render

app = Typer()

Expand Down
1 change: 1 addition & 0 deletions src/dspygen/subcommands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""dspygen package."""
2 changes: 1 addition & 1 deletion src/dspygen/subcommands/command_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import typer

from typetemp.functional import render
from dspygen.typetemp.functional import render

app = typer.Typer(help="""Generate new sub commands or add to existing ones.""")

Expand Down
3 changes: 0 additions & 3 deletions src/dspygen/subcommands/module_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import os

import typer
from pydantic import BaseModel, Field

from dspygen.modules.gen_dspy_module import gen_dspy_module_call
from dspygen.modules.gen_pydantic_instance_module import gen_pydantic_instance_call
from dspygen.modules.file_name_module import file_name_call
from typetemp.functional import render
from dspygen.utils.dspy_tools import init_dspy
from dspygen.utils.file_tools import dspy_modules_dir, source_dir

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from jinja2 import Environment, FileSystemLoader

from typetemp.extension.faker_extension import FakerExtension
from typetemp.extension.inflection_extension import InflectionExtension
from dspygen.typetemp.extension.faker_extension import FakerExtension
from dspygen.typetemp.extension.inflection_extension import InflectionExtension


class TypedEnvironment(Environment):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from jinja2 import FileSystemLoader
from jinja2.nativetypes import NativeEnvironment

from typetemp.extension.faker_extension import FakerExtension
from typetemp.extension.inflection_extension import InflectionExtension
from dspygen.typetemp.extension.faker_extension import FakerExtension
from dspygen.typetemp.extension.inflection_extension import InflectionExtension


class TypedNativeEnvironment(NativeEnvironment):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
from pathlib import Path

from typetemp.environment.typed_environment import environment
from typetemp.environment.typed_native_environment import native_environment
from dspygen.typetemp.environment.typed_environment import environment
from dspygen.typetemp.environment.typed_native_environment import native_environment

_env = environment
_native_env = native_environment
Expand Down
File renamed without changes.
Loading

0 comments on commit f5ffb5f

Please sign in to comment.