Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
anpl
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ziyuan Nan
anpl
Commits
9fcdba96
Commit
9fcdba96
authored
May 16, 2023
by
nzy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FINISH
parent
e1a5c292
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
18 deletions
+27
-18
anpl/anpl.py
+1
-1
robotA.py
+1
-1
robotB.py
+24
-15
utils.py
+1
-1
No files found.
anpl/anpl.py
View file @
9fcdba96
...
@@ -145,7 +145,7 @@ black, blue, red, green, yellow, grey, pink, orange, teal, maroon = range(10)
...
@@ -145,7 +145,7 @@ black, blue, red, green, yellow, grey, pink, orange, teal, maroon = range(10)
return
[
f
.
name
for
f
in
self
.
funs
.
values
()
if
not
f
.
code
]
return
[
f
.
name
for
f
in
self
.
funs
.
values
()
if
not
f
.
code
]
def
user_known_funs
(
self
)
->
list
[
str
]:
def
user_known_funs
(
self
)
->
list
[
str
]:
return
[
f
.
name
for
f
in
self
.
funs
.
values
()]
return
[
f
.
name
for
f
in
self
.
funs
.
values
()
if
f
.
code_from_user
or
f
.
prompt_from_user
]
def
to_python
(
self
,
name
:
Optional
[
str
]
=
None
,
for_user
=
False
)
->
str
:
def
to_python
(
self
,
name
:
Optional
[
str
]
=
None
,
for_user
=
False
)
->
str
:
funs_name
=
reversed
(
self
.
find_dependencies
(
name
or
self
.
entry
))
funs_name
=
reversed
(
self
.
find_dependencies
(
name
or
self
.
entry
))
...
...
robotA.py
View file @
9fcdba96
...
@@ -71,7 +71,7 @@ is_correct = anpl_check(anpl, anpl.entry)
...
@@ -71,7 +71,7 @@ is_correct = anpl_check(anpl, anpl.entry)
while
not
is_correct
:
while
not
is_correct
:
system_info
(
"[red]ANPL WRONG[/red] Here is the anpl program."
)
system_info
(
"[red]ANPL WRONG[/red] Here is the anpl program."
)
print_anpl
(
anpl
)
print_anpl
(
anpl
,
for_user
=
True
)
cmd
=
Prompt
.
ask
(
sys_str
+
"Which command would you like to do? [1] Trace [2] Edit [3] Resynthesis [4] Remove IO [5] Quit"
,
choices
=
[
"1"
,
"2"
,
"3"
,
"4"
,
"5"
])
cmd
=
Prompt
.
ask
(
sys_str
+
"Which command would you like to do? [1] Trace [2] Edit [3] Resynthesis [4] Remove IO [5] Quit"
,
choices
=
[
"1"
,
"2"
,
"3"
,
"4"
,
"5"
])
if
cmd
==
"5"
:
if
cmd
==
"5"
:
...
...
robotB.py
View file @
9fcdba96
...
@@ -6,12 +6,22 @@ from anpl.sandbox import import_module_from_string, timeout
...
@@ -6,12 +6,22 @@ from anpl.sandbox import import_module_from_string, timeout
import
numpy
as
np
import
numpy
as
np
import
time
import
time
from
copy
import
deepcopy
from
copy
import
deepcopy
import
re
history
=
[]
history
=
[]
code
=
""
def
print_msg
(
message
):
def
print_msg
(
message
):
role
,
text
=
message
[
"role"
],
message
[
"content"
]
role
,
text
=
message
[
"role"
],
message
[
"content"
]
rich
.
print
(
f
"[blue]{role}[/blue]:"
)
rich
.
print
(
f
"[blue]{role}[/blue]:"
)
print
(
text
)
pattern
=
r'```(.*?)```'
try
:
global
code
code
=
re
.
findall
(
pattern
,
text
,
flags
=
re
.
DOTALL
)[
0
]
.
strip
()
except
Exception
as
e
:
print
(
e
)
code
=
""
text_without_code
=
re
.
sub
(
pattern
,
''
,
text
,
flags
=
re
.
DOTALL
)
print
(
text_without_code
)
def
print_history
():
def
print_history
():
for
i
,
message
in
enumerate
(
history
):
for
i
,
message
in
enumerate
(
history
):
...
@@ -24,7 +34,7 @@ logger = Logger(task_id, "B")
...
@@ -24,7 +34,7 @@ logger = Logger(task_id, "B")
is_correct
=
False
is_correct
=
False
while
not
is_correct
:
while
not
is_correct
:
cmd
=
Prompt
.
ask
(
sys_str
+
"Which command would you like to do? [1] Chat [2] Remove history [3]
Check Code [4] Quit"
,
choices
=
[
"1"
,
"2"
,
"3"
,
"4
"
])
cmd
=
Prompt
.
ask
(
sys_str
+
"Which command would you like to do? [1] Chat [2] Remove history [3]
Quit"
,
choices
=
[
"1"
,
"2"
,
"3
"
])
if
cmd
==
"1"
:
if
cmd
==
"1"
:
system_info
(
"Please input your description or IO examples"
)
system_info
(
"Please input your description or IO examples"
)
...
@@ -62,12 +72,19 @@ while not is_correct:
...
@@ -62,12 +72,19 @@ while not is_correct:
else
:
else
:
logger
.
log
(
"user"
,
"remove"
,
"no history"
)
logger
.
log
(
"user"
,
"remove"
,
"no history"
)
system_info
(
"[red]No history[/red]"
)
system_info
(
"[red]No history[/red]"
)
else
:
quit_time
=
time
.
time
()
if
quit_time
-
logger
.
start_time
<
30
*
60
:
if
Confirm
.
ask
(
sys_str
+
"Less than 30 minutes. Do you really want to exit?"
):
logger
.
log
(
"user"
,
"quit"
,
"force"
)
break
else
:
break
elif
cmd
==
"3"
:
# print("here is code")
system_info
(
"Code will be executed from main function. The signature of main function should be `def main(input_grid):`"
)
# print(code)
system_info
(
"Please enter your code"
)
# print("code end")
code
=
multiline_input
()
logger
.
log
(
"system"
,
"check"
,
code
)
logger
.
log
(
"user"
,
"check"
,
code
)
try
:
try
:
m
=
import_module_from_string
(
code
)
m
=
import_module_from_string
(
code
)
inp_t
=
deepcopy
(
inp
)
inp_t
=
deepcopy
(
inp
)
...
@@ -91,13 +108,5 @@ while not is_correct:
...
@@ -91,13 +108,5 @@ while not is_correct:
rich
.
print
(
rich_dumps
(
out
))
rich
.
print
(
rich_dumps
(
out
))
rich
.
print
(
"[green]Textual Output[/green]"
)
rich
.
print
(
"[green]Textual Output[/green]"
)
print
(
" "
.
join
(
out
.
__repr__
()
.
split
()))
print
(
" "
.
join
(
out
.
__repr__
()
.
split
()))
else
:
quit_time
=
time
.
time
()
if
quit_time
-
logger
.
start_time
<
30
*
60
:
if
Confirm
.
ask
(
sys_str
+
"Less than 30 minutes. Do you really want to exit?"
):
logger
.
log
(
"user"
,
"quit"
,
"force"
)
break
else
:
break
logger
.
log
(
"system"
,
"exit"
,
str
(
is_correct
))
logger
.
log
(
"system"
,
"exit"
,
str
(
is_correct
))
utils.py
View file @
9fcdba96
...
@@ -71,7 +71,7 @@ sys_str = "[bold red]SYSTEM: [/bold red]"
...
@@ -71,7 +71,7 @@ sys_str = "[bold red]SYSTEM: [/bold red]"
def
system_info
(
text
):
def
system_info
(
text
):
print
(
sys_str
+
text
)
print
(
sys_str
+
text
)
def
print_anpl
(
anpl
,
for_user
=
False
):
def
print_anpl
(
anpl
,
for_user
):
print
(
Syntax
(
anpl
.
to_python
(
for_user
=
for_user
),
"python"
))
print
(
Syntax
(
anpl
.
to_python
(
for_user
=
for_user
),
"python"
))
def
print_text_IOExamples
(
ios
:
list
[
IOExample
]):
def
print_text_IOExamples
(
ios
:
list
[
IOExample
]):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment