Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/rag/rag_library1.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ text:
return:
lang: python
code: |
import examples.rag.rag as rag
import rag
result = rag.parse(filename, chunk_size, chunk_overlap)
- def: rag_index
function:
Expand All @@ -22,7 +22,7 @@ text:
return:
lang: python
code: |
import examples.rag.rag as rag
import rag
result = rag.rag_index(inp, encoder_model, embed_dimension, database_name, collection_name)
- def: rag_retrieve
function:
Expand All @@ -34,5 +34,5 @@ text:
return:
lang: python
code: |
import examples.rag.rag as rag
import rag
result = rag.rag_retrieve(inp, encoder_model, limit, database_name, collection_name)
6 changes: 4 additions & 2 deletions src/pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ def process_call_code(
match block.lang:
case "python":
try:
result = call_python(code_s, scope)
result = call_python(code_s, scope, state)
background = PdlList(
[PdlDict({"role": state.role, "content": lazy_apply(str, result), "defsite": block.pdl__id})] # type: ignore
)
Expand Down Expand Up @@ -1621,12 +1621,14 @@ def process_call_code(
__PDL_SESSION = types.SimpleNamespace()


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


Expand Down