Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI code interpreter (draft) #37

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
hack for gpt-3.5
  • Loading branch information
kharvd committed Jun 25, 2023
commit e6520008db0f69de104dfac39713b468ae0459f6
2 changes: 1 addition & 1 deletion gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __init__(self, assistant: Assistant, markdown: bool, show_price: bool):
listeners.append(PriceChatListener(assistant))

if os.environ.get("GPTCLI_ALLOW_CODE_EXECUTION") == "1":
listeners.append(CodeInterpreterListener("python_eval"))
listeners.append(CodeInterpreterListener("python"))

listener = CompositeChatListener(listeners)
super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion gptcli/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

FUNCTIONS_SCHEMA = [
{
"name": "python_eval",
"name": "python",
"description": "Evaluate an arbitrary Python snippet",
"parameters": {
"type": "object",
Expand Down
11 changes: 10 additions & 1 deletion gptcli/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ def _handle_function_call(self, function_call: FunctionCall) -> Message:
function_name = function_call.get("name", "null")

function_result = None

try:
function_arguments = json.loads(function_call["arguments"])
arguments = function_call.get("arguments", "{}")
if arguments.startswith("{"):
function_arguments = json.loads(arguments)
else:
# HACK: gpt-3.5-turbo sometimes returns a string instead of a dict for python calls
function_arguments = {
"source": function_call.get("arguments", ""),
}

function_result = self.listener.on_function_call(
function_name, **function_arguments
)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ prompt-toolkit==3.0.38
pytest==7.3.1
PyYAML==6.0
rich==13.3.2
tiktoken==0.3.3
tiktoken==0.4.0
tokenizers==0.13.3
typing_extensions==4.5.0
jupyter-client==8.2.0
Expand Down
Loading