Skip to content

Commit 16d35e6

Browse files
vazirimclaudiosv
authored andcommitted
Change to sys.path for python code block (#931)
Signed-off-by: Mandana Vaziri <[email protected]> Signed-off-by: Claudio Spiess <[email protected]>
1 parent 3106dce commit 16d35e6

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

examples/rag/rag_library1.pdl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ text:
1010
return:
1111
lang: python
1212
code: |
13-
import examples.rag.rag as rag
13+
import rag
1414
result = rag.parse(filename, chunk_size, chunk_overlap)
1515
- def: rag_index
1616
function:
@@ -22,7 +22,7 @@ text:
2222
return:
2323
lang: python
2424
code: |
25-
import examples.rag.rag as rag
25+
import rag
2626
result = rag.rag_index(inp, encoder_model, embed_dimension, database_name, collection_name)
2727
- def: rag_retrieve
2828
function:
@@ -34,5 +34,5 @@ text:
3434
return:
3535
lang: python
3636
code: |
37-
import examples.rag.rag as rag
37+
import rag
3838
result = rag.rag_retrieve(inp, encoder_model, limit, database_name, collection_name)

src/pdl/pdl_interpreter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ def process_call_code(
16561656
match block.lang:
16571657
case "python":
16581658
try:
1659-
result = call_python(code_s, scope)
1659+
result = call_python(code_s, scope, state)
16601660
background = PdlList(
16611661
[
16621662
PdlDict(
@@ -1770,12 +1770,14 @@ def process_call_code(
17701770
__PDL_SESSION = types.SimpleNamespace()
17711771

17721772

1773-
def call_python(code: str, scope: ScopeType) -> PdlLazy[Any]:
1773+
def call_python(code: str, scope: ScopeType, state: InterpreterState) -> PdlLazy[Any]:
17741774
my_namespace = types.SimpleNamespace(PDL_SESSION=__PDL_SESSION, **scope)
1775+
sys.path.append(str(state.cwd))
17751776
exec(code, my_namespace.__dict__) # nosec B102
17761777
# [B102:exec_used] Use of exec detected.
17771778
# This is the code that the user asked to execute. It can be executed in a docker container with the option `--sandbox`
17781779
result = my_namespace.result
1780+
sys.path.pop()
17791781
return PdlConst(result)
17801782

17811783

0 commit comments

Comments
 (0)