Skip to content

Commit 08837a3

Browse files
authored
Merge pull request #101 from tianyaohu/git_issue_gen
Add examples: +git_issue generator with command line error output
2 parents fdd20b9 + 6576f6e commit 08837a3

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

examples/git_issue.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import ell
2+
import os
3+
4+
from ell.stores.sql import SQLiteStore
5+
6+
ell.config.verbose = True
7+
8+
@ell.lm(model="gpt-4o-mini", temperature=0.1)
9+
def generate_description(about : str):
10+
return [
11+
ell.system(f"""Provide a clear and concise description of what the issue is. Include any relevant information that helps to explain the problem.
12+
This section should help the reader understand the context and the impact of the issue.
13+
Output only the description as a string and nothing else"""),
14+
ell.user(f"Generate a issue description about {about}."),
15+
]
16+
17+
@ell.lm(model="gpt-4o-mini", temperature=0.1)
18+
def generate_python_code_for_A_output_B(A: str, B: str = 'nothing'):
19+
return [
20+
ell.system(f"""You are a world-class python developer. Do not include code that can leak important privacy information that maybe of concern.
21+
Check the code carefully in terms of correctness, style and efficiency.
22+
Do not format in markdown. You are directly outputting python code.
23+
Do not include use code to get system information that is not important to github issue.
24+
You can also do multiline code if you need ot import any dependency. Do not write wrap any code in functions.
25+
"""),
26+
ell.user(f"Write the python code for {A} and the code should have a local 'OUTPUT' as {B}. Only output the code and nothing else."),
27+
]
28+
29+
@ell.lm(model="gpt-4o", temperature=0.1)
30+
def generate_issue(
31+
error: str,
32+
):
33+
#generate description
34+
description = generate_description(error)
35+
36+
# Define topics for system information
37+
info_topics = ['operating system info',
38+
'Hardware',
39+
]
40+
41+
# Generate Python code for each info topic
42+
ls_code = [generate_python_code_for_A_output_B(i, 'string') for i in info_topics]
43+
system_info = []
44+
# Execute each generated code snippet
45+
for code in ls_code:
46+
local_vars = {}
47+
exec(code, globals(), local_vars)
48+
# Record the output
49+
system_info.append(local_vars.get("OUTPUT"))
50+
51+
return [
52+
ell.system("You are an expert at Markdown and at writing git issues. Output Markdown and nothing else"),
53+
ell.user(f"Write a git issue with the following description: {description}. Here is the system information: {system_info}"),
54+
]
55+
56+
if __name__ == "__main__":
57+
58+
store = SQLiteStore('sqlite_example')
59+
store.install(autocommit=True)
60+
61+
# This is an example from ell's early day error
62+
error_console_output = """
63+
(ell_lab) D:\\dev\\ell>D:/anaconda/envs/ell_lab/python.exe d:/dev/ell/examples/multilmp.py
64+
before ideas 1232131
65+
╔═════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
66+
║ generate_story_ideas(a dog) # (notimple...)
67+
╠═════════════════════════════════════════════════════════════════════════════════════════════════════════════╣
68+
║ Prompt:
69+
╟─────────────────────────────────────────────────────────────────────────────────────────────────────────────╢
70+
│ system: You are an expert story ideator. Only answer in a single sentence.
71+
72+
│ user: Generate a story idea about a dog.
73+
╟─────────────────────────────────────────────────────────────────────────────────────────────────────────────╢
74+
║ Output[0 of 4]:
75+
╟─────────────────────────────────────────────────────────────────────────────────────────────────────────────╢
76+
│ assistant: A rescue dog with the ability to sense emotions helps a grieving child heal after the
77+
│ loss of a loved one, leading them both on a journey of friendship and discovery.
78+
╚═════════════════════════════════════════════════════════════════════════════════════════════════════════════╝
79+
Traceback (most recent call last):
80+
File "d:\\dev\\ell\\examples\\multilmp.py", line 53, in <module>
81+
story = write_a_really_good_story("a dog")
82+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
File "D:\\dev\\ell\\ell\\src\\ell\\decorators.py", line 207, in wrapper
84+
else fn(*fn_args, _invocation_origin=invocation_id, **fn_kwargs, )
85+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
File "D:\\dev\\ell\\ell\\src\\ell\\decorators.py", line 150, in wrapper
87+
res = fn(*fn_args, **fn_kwargs)
88+
^^^^^^^^^^^^^^^^^^^^^^^^^
89+
File "d:\\dev\\ell\\examples\\multilmp.py", line 32, in write_a_really_good_story
90+
ideas = generate_story_ideas(about, lm_params=(dict(n=4)))
91+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92+
File "D:\\dev\\ell\\ell\\src\\ell\\decorators.py", line 216, in wrapper
93+
fn_closure, _uses = ell.util.closure.lexically_closured_source(func_to_track)
94+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95+
File "D:\\dev\\ell\\ell\\src\\ell\\util\\closure.py", line 306, in lexically_closured_source
96+
_, fnclosure, uses = lexical_closure(func, initial_call=True)
97+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98+
File "D:\\dev\\ell\\ell\\src\\ell\\util\\closure.py", line 250, in lexical_closure
99+
dep, _, dep_uses = lexical_closure(
100+
^^^^^^^^^^^^^^^^
101+
File "D:\\dev\\ell\\ell\\src\\ell\\util\\closure.py", line 196, in lexical_closure
102+
ret = lexical_closure(
103+
^^^^^^^^^^^^^^^^
104+
File "D:\\dev\\ell\\ell\\src\\ell\\util\\closure.py", line 140, in lexical_closure
105+
source = getsource(func, lstrip=True)
106+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107+
File "D:\\anaconda\\envs\\ell_lab\\Lib\\site-packages\\dill\\source.py", line 374, in getsource
108+
lines, lnum = getsourcelines(object, enclosing=enclosing)
109+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110+
File "D:\\anaconda\\envs\\ell_lab\\Lib\\site-packages\\dill\\source.py", line 345, in getsourcelines
111+
code, n = getblocks(object, lstrip=lstrip, enclosing=enclosing, locate=True)
112+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113+
File "D:\\anaconda\\envs\\ell_lab\\Lib\\site-packages\\dill\\source.py", line 271, in getblocks
114+
lines, lnum = findsource(object)
115+
^^^^^^^^^^^^^^^^^^
116+
File "D:\\anaconda\\envs\\ell_lab\\Lib\\site-packages\\dill\\source.py", line 215, in findsource
117+
line = lines[lnum]
118+
~~~~~^^^^^^
119+
IndexError: list index out of range
120+
"""
121+
122+
# error_console_output = input("Enter the console output of the error. ").strip()
123+
if error_console_output is None or error_console_output == "":
124+
raise ValueError("Error console output is required. Please provide the console output of the error.")
125+
126+
127+
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
128+
output_file = os.path.join(desktop_path, "git_issue.md")
129+
130+
# generate a conda yaml file. Add print for success and filepath.
131+
# env_info = 'generate a .yaml on desktop for the current conda environment. Add print for success and filepath.'
132+
# exec(generate_python_code_for_A_output_B(env_info))
133+
134+
with open(output_file, "w") as f:
135+
f.write(generate_issue(error_console_output))
136+

0 commit comments

Comments
 (0)