Skip to content

Commit 206df2d

Browse files
committed
Change to sys.path for python code block
Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 2492b39 commit 206df2d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

examples/rag/rag_library1.pdl

+3-3
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ def process_call_code(
15431543
match block.lang:
15441544
case "python":
15451545
try:
1546-
result = call_python(code_s, scope)
1546+
result = call_python(code_s, scope, state)
15471547
background = PdlList(
15481548
[PdlDict({"role": state.role, "content": lazy_apply(str, result), "defsite": block.pdl__id})] # type: ignore
15491549
)
@@ -1621,12 +1621,14 @@ def process_call_code(
16211621
__PDL_SESSION = types.SimpleNamespace()
16221622

16231623

1624-
def call_python(code: str, scope: ScopeType) -> PdlLazy[Any]:
1624+
def call_python(code: str, scope: ScopeType, state: InterpreterState) -> PdlLazy[Any]:
16251625
my_namespace = types.SimpleNamespace(PDL_SESSION=__PDL_SESSION, **scope)
1626+
sys.path.append(str(state.cwd))
16261627
exec(code, my_namespace.__dict__) # nosec B102
16271628
# [B102:exec_used] Use of exec detected.
16281629
# This is the code that the user asked to execute. It can be executed in a docker container with the option `--sandbox`
16291630
result = my_namespace.result
1631+
sys.path.pop()
16301632
return PdlConst(result)
16311633

16321634

0 commit comments

Comments
 (0)