#My assistant can't remember it's role and tools

1 messages · Page 1 of 1 (latest)

fleet kayak
#

Hello everyone!
I need your help.
Now I am working with assistant api.
I created assistant with instruction(role) and file search tool. This assistant works well in playground.
But If I use this assistant api with my nodeJS code, it can't remember the role and instructions.
I can't detect the reason.
This is my code.
"
const message = await openai.beta.threads.messages.create(
thread_id,
{
role: "user",
content: msg.body
}
);

let run = await openai.beta.threads.runs.createAndPoll(
    thread_id,
    {
        assistant_id: assistant.id,
        instructions: "You must use file search tool to generate answer",
        tools: [{ "type": "file_search" }]
    }
);

if (run.status === 'completed') {
    const messages = await openai.beta.threads.messages.list(
        run.thread_id
    );
    // for (const message of messages.data.reverse()) {
    //     console.log(`${message.role} > ${message.content[0].text.value}`);
    // }
    let message = messages.data[0];
    console.log("this is the result message=====>", message.role, "  >  ", message.content[0].text.value)
    return message;
} else {
    console.log(run.status);
    return false;
}"

Help me.🙏

fleet kayak
#

I solved this problem by my self.

terse pagoda
#

In the code you've provided, you're creating messages and running the assistant within the same function execution without persisting any state or context between the different API requests.

Here are some steps you could take to ensure that the assistant retains the context:

When initializing the session, make sure to pass the necessary parameters to maintain the context.
If there is a way to specify the conversation history or a session ID, ensure that it's included in each request.
Update the code to correctly handle and pass any context object required by the API for maintaining state.
Unfortunately, without the exact details on how the OpenAI Assistant API expects to maintain context, I can't provide you with precise code. However, here is a general structure for how you might adjust your Node.js code, assuming the API uses a session object to maintain context:

fleet kayak
#

Openai Assistant cannot remember the session information I used to create it, such as instructions and file tools. So you should add this information to thread as user message and tool_resources.
Then assistant can remember it's role.

#

I am curious about the need for assistant instruction.

#

It doesn't work in my code but it works well for playground.

terse pagoda
fleet kayak
#

const thread = await openai.beta.threads.create({
messages: [{
"role": "user",
"content": write the role of the assistant here
}],
tool_resources: {
"file_search": {
"vector_store_ids": ["here is the id of the vectore store you created"]
}
}
});