This is a proof-of-concept (POC) of a customer support automation service built using OpenAI Assistants API.
npm ci- Create an OpenAI assistant by running the following script (assuming that your are in the root of the project). Please add your OPENAI_API_KEY (get it at https://platform.openai.com/api-keys)
node scripts/createOpenAiAssistant.jsAfter this expect to see a new assistant in your OpenAI Assistants dashboard.
In consode or in the dashboard copy the assistant ID (e.g. asst_vh5EBWjfrcj0imtwocWe8lIY).
- Copy the contents of
.env.examplefile to.envfile and update the variables:
CUSTOMER_CONFIGSis an array of objects like{ "x-customer-id": "test-customer", "x-api-key": "secret", "OPENAI_API_KEY": "secret", "OPENAI_ORG": "secret", "OPENAI_ASSISTANT_ID": "secret" }:x-customer-idis a random UUID which you need to generate once and which will serve as the ID of your customer. This value must be sent as the header keyx-customer-idin the requests to[POST] /api/v1/assistant/completeendpointx-api-key- some password to protect the endpoint for this customer (headerx-api-key)OPENAI_API_KEYandOPENAI_ORG- please find those at https://platform.openai.com/api-keysOPENAI_ASSISTANT_ID- the ID of your OpenAI assistant (see step 1 above)
POSTGRESQL_CONNECTION_STRING- a string to connect to your Postgresql DB, e.g.postgres://postgres.bwghlfwqsbwaxnafsysc:[email protected]:6543/postgres(example from https://supabase.com/).
Note that several customers can be added to CUSTOMER_CONFIGS, each with their own OpenAI credentials and assistant.
npm run start:localcurl --location 'localhost:3000/api/v1/assistant/complete' \
--header 'x-api-key: secret' \
--header 'x-customer-id: 74a2aeb0-6963-4eb2-b458-e62877fcc152' \
--header 'Content-Type: application/json' \
--data '{
"userId": "44e2ef2c-89a3-4428-9373-2d18d2e2113f",
"query": "Is it possible to return something I bought on clearance in the store?""
}'Notes:
x-customer-idandx-api-keymust coincide with the values stored in .envuserIdmust be a UUID. Each user gets their own thread with the bot, in which all the messages are processed (so consider the possible effect of the previous conversation turns on the current question). Pass a newuserIdto start conversation from scratch.
Please also see https://github.com/IuriiD/ai24support-openai-pinecone-rag for comparison how the same task can be solved using "custom" retrieval augmented generation (RAG) setup (OpenAI Embeddings and Chat Completion API + Pinecone vector DB).