dspy.PythonInterpreter

dspy.PythonInterpreter

생성된 코드를 로컬 WASM 샌드박스에서 실행하는 인터프리터 팩토리예요. Deno와 Pyodide를 사용해서 신뢰할 수 없는 코드도 호스트 환경과 분리된 채 실행할 수 있어요.

출처: 문서

본문

PythonInterpreter는 Deno와 Pyodide로 Python을 로컬 WASM 샌드박스에서 실행해요.

Deno 설치

권장되는 설치는 Deno를 DSPy와 같은 Python 환경에 두는 거예요.

pip install "dspy[deno]"

deno extra는 공식 Deno Python 배포판(>=2.4.5,<3.0.0)을 설치해요. DSPy는 이 관리형 바이너리가 설치되어 있으면 그것을 선호하므로, Python 의존성 잠금이 Deno 런타임까지 잠궈줘요. 이 extra는 macOS x86-64/arm64, glibc Linux x86-64/arm64, Windows x86-64용 바이너리를 제공하고 환경에 약 40–50 MiB를 더해요.

다른 플랫폼에서는 Deno 설치 안내대로 호환되는 Deno 2.x 릴리스(>=2.0.0,<3.0.0)를 설치하면 돼요. DSPy는 PATH의 deno 실행 파일로 대체하고, PythonInterpreter에 명시적으로 전달된 deno_command가 두 옵션보다 우선해요.

DSPy는 기본 러너의 주변 deno.json, lockfile, package.json, 로컬 node_modules 탐지를 비활성화해요. 따라서 현재 디렉터리나 상위 디렉터리의 package.json은 샌드박스의 고정된 Pyodide 의존성을 다른 곳으로 돌릴 수 없어요. DENO_NO_PACKAGE_JSON 환경 변수는 필요 없어요.

실행 지침

PythonInterpreter.execution_instructions는 Pyodide 실행 환경의 안정적인 제약 조건을 설명해요. 클래스 메타데이터이므로, Deno를 시작하거나 인터프리터를 할당하지 않고도 코드 생성 모듈이 이를 조사할 수 있어요. RLM은 이 지침을 액션 프롬프트에 포함시키고, 어댑터는 이를 모델의 시스템 프롬프트에 렌더링해요.

커스텀 인터프리터 팩토리는 자신만의 execution_instructions 문자열을 제공할 수 있어요. 이 메타데이터는 선택사항이라서, 없는 팩토리도 유효하며 RLM의 일반 액션 프롬프트를 사용해요.

::: dspy.PythonInterpreter
    handler: python
    options:
        members:
            - __call__
            - execute
            - shutdown
            - start
        show_source: true
        show_root_heading: true
        heading_level: 2
        docstring_style: google
        show_root_full_path: true
        show_object_full_path: false
        separate_signature: false
        inherited_members: true

더 알아보기 (Learn more)