Skip to content

Commit

Permalink
Adding first file creation loop
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchatmangpt committed Mar 22, 2024
1 parent f4fff2f commit ac491d4
Show file tree
Hide file tree
Showing 29 changed files with 1,044 additions and 66 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.3.20"
version = "2024.3.22"
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 <info@chatmangpt.com>"]
readme = "README.md"
Expand Down
72 changes: 12 additions & 60 deletions src/dspygen/dsl/examples/example_pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,77 +1,29 @@
lm_models:
- label: "default"
name: "OpenAI"
args:
model: "gpt-3.5-turbo"
max_tokens: 4096
- label: "fast"
name: "OpenAI"
args:
model: "gpt-3.5-turbo"
max_tokens: 2048
- label: "slow"
name: "T5Large"
args:
model: "fine-tuned-t5-large-1234"
max_tokens: 100

rm_models:
- label: "default"
name: "ColBERTv2"
- label: "product_features"
name: "prd_feats.csv"
- label: "user_feedback"
name: "db://user_feedback"
query: "SELECT * FROM user_feedback"

signatures:
- name: "ProcessDataSignature"
docstring: "Processes raw data to synthesize into a structured format suitable for report generation."
inputs:
- name: "raw_data"
desc: "Raw data input that needs processing."
- name: "data_format"
desc: "The desired format of the output data."
outputs:
- name: "processed_data"
desc: "Data processed into a structured format."
- name: "GenerateReportSignature"
docstring: "Generates a comprehensive report from structured data."
- name: "GenerateGherkinSignature"
docstring: "Generates a comprehensive gherkin from structured data."
inputs:
- name: "processed_data"
desc: "Structured data to be included in the report."
- name: "report_template"
desc: "Template specifying the report's format and structure."
desc: "Structured data to be included in the gherkin."
outputs:
- name: "report"
desc: "The final report generated from the structured data."
- name: "gherkin"
desc: "The final gherkin generated from the structured data."

lm_modules:
- name: "DataProcessorModule"
signature: "ProcessDataSignature"
predictor: "Predict"
args:
- name: "raw_data"
value: "{{ user_input }}"
- name: "data_format"
value: "JSON"

- name: "ReportGeneratorModule"
signature: "GenerateReportSignature"
- name: "GherkinGeneratorModule"
signature: "GenerateGherkinSignature"
predictor: "ChainOfThought"
args:
- name: "report_template"
value: "StandardReportTemplate"
- name: "gherkin_scenarios"
value: "StandardGherkinTemplate"

steps:
- module: "DataProcessorModule"
lm_model: "default"
args:
raw_data: "id, name, age\n1, John, 25\n2, Jane, 30"
data_format: "YAML"
- file: "feature_list.yaml"

- module: "ReportGeneratorModule"
- module: "GherkinGeneratorModule"
lm_model: "fast"
args:
processed_data: "{{ processed_data }}"
report_template: "templates/standard_report.html"
processed_data: "{{ processed_data }}"
5 changes: 4 additions & 1 deletion src/dspygen/dsl/utils/dsl_rm_module_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def _get_rm_module_instance(pipeline, rendered_args, step):
Get the module instance for a given step from the top level definition or load the module.
Uses the DSLModule class from dspygen.modules.dsl_module to handle modules defined in the pipeline YAML.
"""
return DataRetriever(**rendered_args, pipeline=pipeline, step=step)
# Get the file_path from the pipeline.context or rendered_args
file_path = pipeline.context.get("file_path", rendered_args.get("file_path"))

return DataRetriever(file_path=file_path, pipeline=pipeline, step=step, **rendered_args)


Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';

interface Document {
id: string;
name: string;
url: string;
}

const DocumentManagement: React.FC = () => {
const [documents, setDocuments] = useState<Document[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string>('');

useEffect(() => {
setLoading(true);
axios
.get('/api/documents')
.then((res) => {
setDocuments(res.data);
setLoading(false);
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
}, []);

const uploadDocument = (file: File) => {
setLoading(true);
const formData = new FormData();
formData.append('file', file);
axios
.post('/api/documents', formData)
.then((res) => {
setDocuments([...documents, res.data]);
setLoading(false);
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};

const downloadDocument = (id: string) => {
setLoading(true);
axios
.get(`/api/documents/${id}`)
.then((res) => {
const link = document.createElement('a');
link.href = res.data.url;
link.download = res.data.name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
setLoading(false);
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};

const deleteDocument = (id: string) => {
setLoading(true);
axios
.delete(`/api/documents/${id}`)
.then(() => {
setDocuments(documents.filter((doc) => doc.id !== id));
setLoading(false);
})
.catch((err) => {
setError(err.message);
setLoading(false);
});
};

return (
<div>
{loading && <p>Loading...</p>}
{error && <p>{error}</p>}
<input type="file" onChange={(e) => uploadDocument(e.target.files[0])} />
<ul>
{documents.map((doc) => (
<li key={doc.id}>
<p>{doc.name}</p>
<button onClick={() => downloadDocument(doc.id)}>Download</button>
<button onClick={() => deleteDocument(doc.id)}>Delete</button>
</li>
))}
</ul>
</div>
);
};

export default DocumentManagement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useState } from 'react';

interface SignaturePlacementProps {
document: Document;
}

const SignaturePlacement: React.FC<SignaturePlacementProps> = ({ document }) => {
const [signature, setSignature] = useState<Signature | null>(null);

const handleSignatureFieldClick = (event: React.MouseEvent<HTMLDivElement>) => {
const signatureField = event.currentTarget;
const signature = document.getSignature(signatureField.id);
setSignature(signature);
};

return (
<div>
<Document document={document} />
<SignatureField onClick={handleSignatureFieldClick} />
{signature && <SignaturePreview signature={signature} />}
</div>
);
};

export default SignaturePlacement;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { useState } from 'react';

const CustomSigningInstructions = () => {
const [customInstructions, setCustomInstructions] = useState('');

const handleCustomInstructionsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setCustomInstructions(e.target.value);
};

const handleSaveCustomInstructions = () => {
// save custom instructions
};

return (
<div>
<button onClick={handleSaveCustomInstructions}>Add Custom Instructions</button>
<input type="text" value={customInstructions} onChange={handleCustomInstructionsChange} />
<p>{customInstructions}</p>
</div>
);
};
```
18 changes: 18 additions & 0 deletions src/dspygen/experiments/react_code_gen/document-download.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { useState, useEffect } from 'react';

const DocumentDownload = () => {
const [downloaded, setDownloaded] = useState(false);

useEffect(() => {
if (downloaded) {
// download document
}
}, [downloaded]);

return (
<div>
<button onClick={() => setDownloaded(true)}>Download</button>
</div>
);
};
```
104 changes: 104 additions & 0 deletions src/dspygen/experiments/react_code_gen/document-preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useState } from 'react';
import DocumentPreview from './DocumentPreview';

const DocumentPreviewPage = () => {
const [document, setDocument] = useState(null);
const [showPreview, setShowPreview] = useState(false);
const [showPrintOptions, setShowPrintOptions] = useState(false);
const [showShareOptions, setShowShareOptions] = useState(false);
const [showDownloadOptions, setShowDownloadOptions] = useState(false);
const [selectedShareOption, setSelectedShareOption] = useState(null);
const [selectedPrintOption, setSelectedPrintOption] = useState(null);

const handleDocumentClick = () => {
setShowPreview(true);
};

const handlePreviewClose = () => {
setShowPreview(false);
};

const handlePrintClick = () => {
setShowPrintOptions(true);
};

const handlePrintOptionSelect = (option) => {
setSelectedPrintOption(option);
};

const handlePrint = () => {
// send document to printer with selected options
};

const handleShareClick = () => {
setShowShareOptions(true);
};

const handleShareOptionSelect = (option) => {
setSelectedShareOption(option);
};

const handleShare = () => {
// share document through selected option
};

const handleDownloadClick = () => {
setShowDownloadOptions(true);
};

const handleDownload = () => {
// download document to user's device
};

return (
<div>
<h1>Document Preview Page</h1>
<button onClick={handleDocumentClick}>Click to view document</button>
{showPreview && (
<DocumentPreview
document={document}
onClose={handlePreviewClose}
onPrint={handlePrintClick}
onShare={handleShareClick}
onDownload={handleDownloadClick}
/>
)}
{showPrintOptions && (
<div>
<h2>Select printing options:</h2>
<select onChange={handlePrintOptionSelect}>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<button onClick={handlePrint}>Print</button>
</div>
)}
{showShareOptions && (
<div>
<h2>Select sharing option:</h2>
<select onChange={handleShareOptionSelect}>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<button onClick={handleShare}>Share</button>
</div>
)}
{showDownloadOptions && (
<div>
<h2>Select download option:</h2>
<select>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
<button onClick={handleDownload}>Download</button>
</div>
)}
</div>
);
};

export default DocumentPreviewPage;
```
Loading

0 comments on commit ac491d4

Please sign in to comment.