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

fix for running with openai model, support arrays as tool inputs #321

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ data/
data.zip
*.DS_store

.idea/
.venv/
.python-version

__MACOSX/

run.bash
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ peft==0.3.0
langchain==0.0.229
deepspeed==0.9.2
sentence_transformers==2.2.2
openai==0.28.0
huggingface-hub==0.25.2
tensorboard
openai
scipy
termcolor
flask
flask_cors
sentence_transformers
13 changes: 8 additions & 5 deletions toolbench/inference/Downstream_tasks/rapidapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ def api_json_to_openai_json(self, api_json,standard_tool_name):
map_type = {
"NUMBER": "integer",
"STRING": "string",
"BOOLEAN": "boolean"
"BOOLEAN": "boolean",
"ARRAY": "array",
"integer": "integer",
"number": "number",
"array": "array",
}

pure_api_name = change_name(standardize(api_json["api_name"]))
Expand All @@ -219,10 +223,6 @@ def api_json_to_openai_json(self, api_json,standard_tool_name):
param_type = map_type[para["type"]]
else:
param_type = "string"
prompt = {
"type":param_type,
"description":para["description"][:description_max_length],
}

default_value = para['default']
if len(str(default_value)) != 0:
Expand All @@ -237,6 +237,9 @@ def api_json_to_openai_json(self, api_json,standard_tool_name):
"description":para["description"][:description_max_length]
}

if "items" in para:
prompt["items"] = para["items"]

templete["parameters"]["properties"][name] = prompt
templete["parameters"]["required"].append(name)
for para in api_json["optional_parameters"]:
Expand Down
9 changes: 6 additions & 3 deletions toolbench/inference/LLM/chatgpt_function_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import random


OAI_MODEL = "gpt-3.5-turbo-0125"


@retry(wait=wait_random_exponential(min=1, max=40), stop=stop_after_attempt(3))
def chat_completion_request(key, messages, functions=None,function_call=None,key_pos=None, model="gpt-3.5-turbo-16k-0613",stop=None,process_id=0, **args):
def chat_completion_request(key, messages, functions=None,function_call=None,key_pos=None, model=OAI_MODEL,stop=None,process_id=0, **args):
use_messages = []
for message in messages:
if not("valid" in message.keys() and message["valid"] == False):
Expand All @@ -29,7 +32,7 @@ def chat_completion_request(key, messages, functions=None,function_call=None,key
json_data.update({"function_call": function_call})

try:
if model == "gpt-3.5-turbo-16k-0613":
if model == OAI_MODEL:
openai.api_key = key
else:
raise NotImplementedError
Expand All @@ -45,7 +48,7 @@ def chat_completion_request(key, messages, functions=None,function_call=None,key
return e

class ChatGPTFunction:
def __init__(self, model="gpt-3.5-turbo-16k-0613", openai_key=""):
def __init__(self, model=OAI_MODEL, openai_key=""):
self.model = model
self.conversation_history = []
self.openai_key = openai_key
Expand Down