Create context in chat completions

Hi! I am making a chatbot with Completions since assistants is too slow, the thing is that I need a context and I currently set up the context as openAI says and I feel that it is much more ““dumb”” than assistants in that sense, any solution for me to have the context and understand it better?
thx! :smile:

You are looking for RAG.

GraphRAG if you ask me and if you got a few years to finish it. Or else just go with vectordb.

Start by storing all the user and assistant messages in a database and send the latest ones (let’s say, 10) to the array of messages, along with the new user message on each completion call.

After that, explore new ways to feed to the assistant important data which was previously mentioned by the user in the past.

For example, you could have an additional “assistant” whose purpose is to analyze the last user message and use function calling to return a string with important data extracted from the message.

You would then save this data in your database and pass it as context on each completion call.

There’s lots of ways to do it, but I recommend creating a solution from scratch for your use case instead of building on top of existing libraries.

That is what I do at the moment, I have a father who dissects the prompt and sends it to his children, the children’s response is sent to the parent and the parent responds, even so I feel that many things escape from the context thx :grinning:

You should also check out vector db. Ask ChatGPT for an example code using faiss.

@celia.stelorder Give us a real example of a behavior which does not work as expected, along with your code and we could try to give you a more detailed solution

Let’s see, it is difficult to explain but I am going to simplify it, it is a chatbot for an ERP, the point is that it is to create, for example, commercial documents, products, clients… And I have a parent completions that gives me the section and pieces of optimized prompt for the child completions that already reaches the section and for example the createProduct of my factory, the point is that sometimes, for example, I tell it: create the client Alex and a sales budget, and create the client correctly and for example if not I was able to create the budget because I didn’t have a product, well I didn’t believe it, it returns what I created the client and not the budget and that’s fine but when I tell it the product for which I created the budget it duplicates the above and creates the duplicate client, and so on with many use cases

                    var messagedelchois = choice.message
                    messages.add(messagedelchois)
                    choice.message.toolCalls?.forEach { toolCall ->

                        responseString += instructionsService.doAction(toolCall.function, assistantDTO)
                        tool = mapOf("type" to "object", "text" to responseString)
                        responseString = ""
                        val message = Message(
                            role = "tool",
                            content = objectMapper.writeValueAsString(tool),
                            toolCallId = toolCall.id
                        )

                        messages.add(message)

                    }

Think the issue lies on the system you’re building rather than the context. If you ask the assistant “Now, create a budget for the client which I just created” your code (not the assistant) should identify if the client exists before proceeding. You could achieve that by making a separate call asking the assistant to return the name of the client in a function call, then perform a query on your database using that name and finally check if there’s a result.

You might find this article useful:

1 Like