Skip to content

Instantly share code, notes, and snippets.

@seanchatmangpt
seanchatmangpt / function_call.py
Created February 27, 2024 19:16
Function Calling with DSPy
import ast
import dspy
from dspygen.utils.dspy_tools import init_dspy
def get_current_weather(location: str, temperature_unit: str) -> str:
"""
Get the current weather for a given location in the specified format.
import asyncio
from livingcharter._subcommands import create_yaml
import os
import streamlit as st
import yaml
import streamlit_pydantic as sp
from typing import List, Dict
@seanchatmangpt
seanchatmangpt / model_maker.py
Created February 23, 2024 00:48
Simplest pydantic instance creator.
import ast
import inspect
import dspy
from typing import Type
from pydantic import BaseModel
class User(BaseModel):
name: str
@seanchatmangpt
seanchatmangpt / chatgpt_conversation_parser.py
Created February 16, 2024 23:07
ChatGPT Parser with Pydantic Models
import ijson
import tiktoken
# Define the path to your large JSON file
json_file_path = "data/conversations.json"
from pydantic import BaseModel, Field, ValidationError
from typing import List, Optional, Any
@seanchatmangpt
seanchatmangpt / gen_cli_from_model.py
Created February 15, 2024 04:36
Generate Typer CLI and tests from prompt
import inspect
from jinja2 import Environment, FileSystemLoader
from pydantic import BaseModel, Field
from typing import List
from rdddy.generators.gen_pydantic_instance import GenPydanticInstance
@seanchatmangpt
seanchatmangpt / gen_python_primitive.py
Created February 14, 2024 23:01
Generate python primatives with test.
import ast
from dspy import Assert
from rdddy.generators.gen_module import GenModule
def is_primitive_type(data_type):
primitive_types = {int, float, str, bool, list, tuple, dict, set}
@seanchatmangpt
seanchatmangpt / gen_pydantic_instance.py
Last active February 14, 2024 22:31
Pydantic instance generation with unit tests
import ast
import logging
import inspect
from typing import Type, TypeVar
from dspy import Assert, Module, ChainOfThought, Signature, InputField, OutputField
from pydantic import BaseModel, ValidationError
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
@seanchatmangpt
seanchatmangpt / gen_pydantic_instance.py
Last active September 21, 2024 10:34
Create DSPy Signatures from Pydantic Models
import ast
import logging
import inspect
from typing import Type, TypeVar
from dspy import Assert, Module, ChainOfThought, Signature, InputField, OutputField
from pydantic import BaseModel, ValidationError
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
@seanchatmangpt
seanchatmangpt / actor.py
Last active October 3, 2024 07:15
Actor System and Actor
"""
The Actor Module for Reactive Domain-Driven Design (RDDDY) Framework
---------------------------------------------------------------------
This module implements the core Actor abstraction within the RDDDY framework, providing a robust foundation for building reactive, domain-driven systems that are scalable, maintainable, and capable of handling complex, concurrent interactions. The Actor model encapsulates both state and behavior, allowing for asynchronous message passing as the primary means of communication between actors, thus fostering loose coupling and enhanced system resilience.
### Overview
Actors are the fundamental units of computation in the RDDDY framework. Each actor possesses a unique identity, a mailbox for message queuing, and a set of behaviors to handle incoming messages. The Actor module facilitates the creation, supervision, and coordination of actors within an ActorSystem, ensuring that messages are delivered and processed in a manner consistent with the system's domain-driven de
@seanchatmangpt
seanchatmangpt / gen_cli.py
Created February 9, 2024 23:54
Draft of DSPy CLI
import dsp
import pathlib
import typer
from typetemp.functional import render
import dspy
from utils.create_prompts import create_pydantic_class