Skip to content

Commit

Permalink
Merge branch 'reecelikesramen-issue-287-fix-bv-rendering'
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcowD committed Oct 14, 2024
2 parents 900957e + e3c9f00 commit 0161dee
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
8 changes: 8 additions & 0 deletions ell-studio/src/components/source/DiffRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export function DiffRenderer({
}) {
if (!previousCode) return null;

function removeEllTags(code) {
const ellTagRegex = /\s*#\s*<\/?(BV|BmV|LMP)>/g;
return code.replace(ellTagRegex, '');
}

code = removeEllTags(code);
previousCode = removeEllTags(previousCode);

var previousCodeRows = []
var currentCodeRows = []
const getHighlightedCode = (code, rowsCb) => {
Expand Down
14 changes: 7 additions & 7 deletions ell-studio/src/components/source/LMPSourceView.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const LMPSourceView = ({ lmp, showDependenciesInitial = false, selectedInvocatio
const lmp_name = match[1].split('(')[0];
console.log(lmp_name);
if (uses.some(u => u.name === lmp_name)) {
return `#<LMP>\n${line}\n#</LMP>`;
return `# <LMP>\n${line}\n# </LMP>`;
}
}
return line;
Expand Down Expand Up @@ -121,21 +121,21 @@ const LMPSourceView = ({ lmp, showDependenciesInitial = false, selectedInvocatio

return [{
name: 'boundedVariable',
startTag: '#<BV>',
endTag: '#</BV>',
startTag: '# <BV>',
endTag: '# </BV>',
wrapper: ({children, key, content}) => {
return <>{children}</>
}},
{
name: 'boundedMutableVariable',
startTag: '#<BmV>',
endTag: '#</BmV>',
startTag: '# <BmV>',
endTag: '# </BmV>',
wrapper: mutableBVWrapper
},
{
name: 'usedLMP',
startTag: '#<LMP>',
endTag: '#</LMP>',
startTag: '# <LMP>',
endTag: '# </LMP>',
wrapper: ({children, selectedInvocation, content}) => {
return <UsedLMPWrapper uses={uses} selectedInvocation={selectedInvocation} content={content}>{children}</UsedLMPWrapper>
}
Expand Down
18 changes: 13 additions & 5 deletions examples/bv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,36 @@
- Don't respond in markdown just write code!
- It is extremely important that you don't start you code with ```python <...> """


class Tests:
pass


test = Tests()

another_serializeable_global = ["asd"]


def get_lmp(z = 10):
def get_lmp(z=10):
y = 13
y = z

@ell.simple("gpt-4o-mini", temperature=0.1, max_tokens=6)
def write_a_complete_python_class(user_spec : str):
return [ell.system(f"""You are an mid-tier python programmer capable of interpreting a user's spec and writing a python class to accomidate their request. You should document all your code, and you best practices.
def write_a_complete_python_class(user_spec: str):
return [
ell.system(
f"""You are an mid-tier python programmer capable of interpreting a user's spec and writing a python class to accomidate their request. You should document all your code, and you best practices.
{CODE_INSTURCTIONS} {z} {y} {test} {another_serializeable_global}
"""), ell.user(user_spec)]
"""
),
ell.user(user_spec),
]

return write_a_complete_python_class


if __name__ == "__main__":
ell.init(verbose=True, store=SQLiteStore("./logdir"), autocommit=True)
ell.init(verbose=True, store=("./logdir"), autocommit=True)
# test[0] = "modified at execution :O"
w = get_lmp(z=20)
cls_Def = w("A class that represents a bank")
3 changes: 3 additions & 0 deletions src/ell/studio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def main():
parser.add_argument("--host", default="127.0.0.1", help="Host to run the server on (default: localhost)")
parser.add_argument("--port", type=int, default=5555, help="Port to run the server on (default: 5555)")
parser.add_argument("--dev", action="store_true", help="Run in development mode")
parser.add_argument("--dev-static-dir", default=None, help="Directory to serve static files from in development mode")
parser.add_argument("--open", action="store_true", help="Opens the studio web UI in a browser")
parser.add_argument("--verbose", "-v", action="store_true", help="Enables debug logging for more verbose output")
args = parser.parse_args()
Expand All @@ -64,6 +65,8 @@ async def serve_react_app(full_path: str):
return FileResponse(file_path)
else:
return FileResponse(static_dir / "index.html")
elif args.dev_static_dir:
app.mount("/", StaticFiles(directory=args.dev_static_dir, html=True), name="static")

# Respect Config.create behavior, which has fallback to env vars.
db_path = Path(config.storage_dir) if config.storage_dir else None
Expand Down
12 changes: 6 additions & 6 deletions src/ell/util/closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def _process_other_variable(var_name, var_value, dependencies, uses):
if isinstance(var_value, str) and '\n' in var_value:
dependencies.append(f"{var_name} = '''{var_value}'''")
elif is_immutable_variable(var_value):
dependencies.append(f"#<BV>\n{var_name} = {repr(var_value)}\n#</BV>")
dependencies.append(f"# <BV>\n{var_name} = {repr(var_value)}\n# </BV>")
else:
dependencies.append(f"#<BmV>\n{var_name} = <{type(var_value).__name__} object>\n#</BmV>")
dependencies.append(f"# <BmV>\n{var_name} = <{type(var_value).__name__} object>\n# </BmV>")

def _build_initial_source(imports, dependencies, source):
"""Build the initial source code."""
Expand Down Expand Up @@ -327,11 +327,11 @@ def get_referenced_names(code: str, module_name: str):
Returns:
list: A list of all attributes of the module that are referenced in the code.
"""
# Remove content between #<BV> and #</BV> tags
code = re.sub(r'#<BV>\n.*?\n#</BV>', '', code, flags=re.DOTALL)
# Remove content between # <BV> and # </BV> tags
code = re.sub(r'# <BV>\n.*?\n# </BV>', '', code, flags=re.DOTALL)

# Remove content between #<BmV> and #</BmV> tags
code = re.sub(r'#<BmV>\n.*?\n#</BmV>', '', code, flags=re.DOTALL)
# Remove content between # <BmV> and # </BmV> tags
code = re.sub(r'# <BmV>\n.*?\n# </BmV>', '', code, flags=re.DOTALL)

tree = ast.parse(code)
referenced_names = []
Expand Down
2 changes: 1 addition & 1 deletion src/ell/util/differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def write_commit_message_for_diff(old : str, new : str) -> str:
<Short commit message summarizing all the changes with specificity>:
* <Bulleted list of each specific change>.
"""
clean_program_of_all_bv_tags = lambda program : program.replace("#<BV>", "").replace("#</BV>", "").replace("#<BmV>", "").replace("#</BmV>", "")
clean_program_of_all_bv_tags = lambda program : program.replace("# <BV>", "").replace("# </BV>", "").replace("# <BmV>", "").replace("# </BmV>", "")
old_clean = clean_program_of_all_bv_tags(old)
new_clean = clean_program_of_all_bv_tags(new)

Expand Down

0 comments on commit 0161dee

Please sign in to comment.