mirror of
https://github.com/kennethreitz/langchain.git
synced 2026-06-05 23:00:18 +00:00
combine python files (#256)
This commit is contained in:
+9
-2
@@ -1,4 +1,6 @@
|
||||
"""Mock Python REPL."""
|
||||
import sys
|
||||
from io import StringIO
|
||||
from typing import Dict, Optional
|
||||
|
||||
|
||||
@@ -10,6 +12,11 @@ class PythonREPL:
|
||||
self._globals = _globals if _globals is not None else {}
|
||||
self._locals = _locals if _locals is not None else {}
|
||||
|
||||
def run(self, command: str) -> None:
|
||||
"""Run command with own globals/locals."""
|
||||
def run(self, command: str) -> str:
|
||||
"""Run command with own globals/locals and returns anything printed."""
|
||||
old_stdout = sys.stdout
|
||||
sys.stdout = mystdout = StringIO()
|
||||
exec(command, self._globals, self._locals)
|
||||
sys.stdout = old_stdout
|
||||
output = mystdout.getvalue()
|
||||
return output
|
||||
|
||||
Reference in New Issue
Block a user