Open Jyustin opened 6 months ago
Chat API Assistant Overview Ref: https://platform.openai.com/docs/assistants/overview
Step 1: Create an Assistant An Assistant represents an entity that can be configured to respond to users’ Messages.
Step 2: Create a Thread A Thread represents a conversation. OpenAI recommends creating one Thread per user as soon as the user initiates the conversation.
Step 3: Add a Message to a Thread A Message contains text, and optionally any files that you allow the user to upload. Messages need to be added to a specific Thread. Adding images via message objects like in Chat Completions using GPT-4 with Vision is not supported today.
Step 4: Run the Assistant For the Assistant to respond to the user message, you need to create a Run. This makes the Assistant read the Thread and decide whether to call tools (if they are enabled) or simply use the model to best answer the query. As the run progresses, the assistant appends Messages to the thread with the role="assistant". The Assistant will also automatically decide what previous Messages to include in the context window for the model.
Step 5: Check the Run status By default, a Run goes into the queued state. You can periodically retrieve the Run to check on its status to see if it has moved to completed.
Step 6: Display the Assistant's Response Once the Run completes, you can list the Messages added to the Thread by the Assistant. There can be many messages, including previous conversations. The latest message is in the first_id message.
Backend Backend is composed of a SpringBoot Rest Controller to communicate with ChatGPT. Chat history is persisted in DB using JPA. Chat.java Java POJO used as Entity. Fields
ChatRepository.java JpaRepository for Chat entity Methods
AIChatbotController.java RestController to communicate to the AI engine, in this case ChatGPT, and retrieve responses to user’s queries. URL Mappings
Frontend Frontend is composed of HTML, CSS, and JavaScript. It is based on: https://codepen.io/sajadhsm/pen/odaBdd which provides a chat UI HTML. When a user types in a message and hits Send button, the Controller is invoked. The controller’s reponse is then shown to the user in a conversational style.
Future Changes to the Chat AI Feature:
plan for algorithmic incorporation
public String toString() { String output = ""; if (KeyType.name.equals(this.getKey())) { output += this.name; } else if (KeyType.tokens.equals(this.getKey())) { output += this.tokens; } else if (KeyType.user_key.equals(this.getKey())) { output += this.user_key; } else { output = super.getType() + ": " + this.name + ", " + this.tokens + ", " + this.user_key; } return output; }
plan for websocket implementation use websockets to: store user chat history monitor chat history and block messages that exceed a certain token amount ...
Working on using shivansh chat ai project as a building block to add into our project.
Place Backend Code Link Place Frontend
these links are to project from last tri shivansh worked on. plan is to implement the chat ai feature into our project with Shivansh, Justin, some input from Rachit.