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

Simplify OpenAI VectorSearchRetrieverTool tool execution function #44

Merged
merged 13 commits into from
Jan 16, 2025

Conversation

leonbi100
Copy link
Contributor

@leonbi100 leonbi100 commented Jan 15, 2025

This PR refactors the OpenAI VectorSearchRetrieverTool#execute_tools function to be VectorSearchRetrieverTool#execute. The goal here is to do less of the response parsing and instead only focus on executing the retriever call, which is more in line with how the OpenAI SDK documents function calling.

The new usage pattern is more along the lines of:

dbvs_tool = VectorSearchRetrieverTool("index_name")
tools = [dbvs_tool.tool, ...]
response = openai.chat.completions.create(
  model="gpt-4o",
  messages=initial_messages,
  tools=tools,
)
tool_call = response.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
retriever_resp = vector_search_tool.execute(query=args["query"])

# OpenAI tool names must match the pattern '^[a-zA-Z0-9_-]+$'."
# The '.' from the index name are not allowed
def rewrite_index_name(index_name: str):
return index_name.replace(".", "_")
def get_tool_name():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# OpenAI tool names must match the pattern '^[a-zA-Z0-9_-]+$'."
# The '.' from the index name are not allowed
def rewrite_index_name(index_name: str):
return index_name.replace(".", "_")
def get_tool_name():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to make this into a public API so that we can just officially recommend customers use it to get the name of the vector search tool, but ok to do that in a follow-up

Copy link
Collaborator

@smurching smurching left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@leonbi-db leonbi-db merged commit b6dddc8 into databricks:main Jan 16, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants