seanchatmangpt / dspygen

A Ruby on Rails style framework for the DSPy (Demonstrate, Search, Predict) project for Language Models like GPT, BERT, and LLama.
MIT License
78 stars 19 forks source link

generation outputs to terminal and then inside a wierd place on disk #15

Closed lebsral closed 1 month ago

lebsral commented 1 month ago

this is all directly copy pasted from my zsh terminal. dspygen version 2024.6.19. installed in a fresh environment in a new dspygen generated project.

(dspygen) lars@MacBook-Pro-10 mydspygenproject % dspygen module new -cn CodeGenerator -i "prompt" -o "generated_code"
"""

""" import dspy from dspygen.utils.dspy_tools import init_dspy

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

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, prompt):
    pred = dspy.Predict("prompt -> generated_code")
    self.output = pred(prompt=prompt).generated_code
    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(prompt): """CodeGeneratorModule""" init_dspy()

print(code_generator_call(prompt=prompt))

def code_generator_call(prompt): code_generator = CodeGeneratorModule() return code_generator.forward(prompt=prompt)

def main(): init_dspy() prompt = "" result = code_generator_call(prompt=prompt) print(result)

from fastapi import APIRouter router = APIRouter()

@router.post("/code_generator/") async def code_generator_route(data: dict):

Your code generation logic here

init_dspy()

print(data)
return code_generator_call(**data)

""" import streamlit as st

Streamlit form and display

st.title("CodeGeneratorModule Generator") prompt = st.text_input("Enter prompt")

if st.button("Submit CodeGeneratorModule"): init_dspy()

result = code_generator_call(prompt=prompt)
st.write(result)

"""

if name == "main": main()

Module saved to /Users/lars/anaconda3/envs/dspygen/lib/python3.11/site-packages/dspygen/modules/code_generator_module.py (dspygen) lars@MacBook-Pro-10 mydspygenproject %

seanchatmangpt commented 1 month ago

I will fix that. It's because people working with it create the modules in the cloned project, then move over to their project when tested. I can change it to be local

lebsral commented 1 month ago

Thanks! Any fix that prevents me from screwing things up is always welcome.

seanchatmangpt commented 1 month ago

All you have to do is copy and paste that file to your own project. It won't hurt anything. That is why I just print it to the CLI.

seanchatmangpt commented 1 month ago

Fixed