Cannot guide the assistant to use external querying tools

We are trying to link an external knowledge base to chat gpt. But chatgpt won’t call the given function:

here is the prompt we have:

from openai import OpenAI

client = OpenAI()
assistant = client.beta.assistants.create(
    name="ChatData",
    instructions=(
        "You are a helpful assistant. Do your best to answer the questions. "
    ),
    tools=[
        {
            "name": "get_related_pages",
            "description": (
                "Get some related documents"
            ),
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string"},
                    "where_str": {
                        "type": "string",
                        "description": "a sql-like where string to build filter. you can use `text`, `title` columns in your where clause."
                    },
                    "limit": {"type": "integer", "description": "default to 4"},
                },
                "required": ["subject", "where_str", "limit"],
            },
        },
    ],
    model="gpt-3.5-turbo",
)

we also tried to force the chatgpt to use external knowledge base by

run = client.beta.threads.runs.create(
    thread_id=thread.id,
    assistant_id=assistant.id,
    instructions= "You must use query tools to look up relevant information to every answer user's question.",
)

We never managed to get into require_action state. Could you please take a look at this?

It looks like a wrong API call to Assistants API.

The correct one should look like this:

from openai import OpenAI

client = OpenAI()

assistant = client.beta.assistants.create(
    name="ChatData",
    instructions=(
        "You are a helpful assistant. Do your best to answer the questions. "
    ),
    tools=[
        {
            "type": "function",
            "function": {
                "name": "get_related_pages",
                "description": ("Get some related documents"),
                "parameters": {
                    "type": "object",
                    "properties": {
                        "keywords": {"type": "string", "description": "keywords to describe the subject you want to query."},
                        "where_str": {
                            "type": "string",
                            "description": "a sql-like where string to build filter. you can use `text`, `title` columns in your where clause.",
                        },
                        "limit": {"type": "integer", "description": "default to 4"},
                    },
                    "required": ["keywords", "where_str", "limit"],
                },
            },
        }
    ],
    model="gpt-3.5-turbo",
)
1 Like