hiyaryan / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling distorted thinking and finding alternative modes of thought (i.e. reframing) while cognitive distortions are occurring. The CDJ does that work for you. -- The CDJ is in beta testing!!
https://thecdj.app
3 stars 0 forks source link

Add chat completion. #23

Closed hiyaryan closed 9 months ago

hiyaryan commented 9 months ago

This PR adds the chat functionality. The initial commits to this PR updates the CdGpt assistant to manage chatMessages and distinguish between analysisMessages. It adds a chatSeed message and seeds the chat messages. Additionally, the initial getChatCompletion method is created taking a similar form to getAnalysisCompletion without a required format. These updates have been tested provided the accompanying unit tests.

Note that since there is no required format from gpt, any gpt can be used. This means that getChatCompletion should be updated to accept some chatModel (updating the current model in CdGpt to analysisModel). This will require updating the config model and adding a new field to the Config form.

Finally, the initial commit of this PR adds a method onto the entryConversationSchema called getChatContent that is to be used to get the chat completion whenever they submit a chat request (PUT or POST). This will require updating the controllers used on the chat endpoints. This method has not been tested yet and will require manual testing once the controllers are updated.

hiyaryan commented 9 months ago

The final commits of this PR configures the chat completion and provides the ability for the user to choose separate models for chat and analysis (currently both textfields but the analysis should be a dropdown menu which will be done in a later PR).

Now anytime the user submits a new chat or continues (updates) an existing chat, a fetch request is made to the OpenAI chat completion endpoint with a designated chat model assigned by the user in their Config menu.

Note that a loading sequence is necessary to prevent double (or more) posting. In a future designated PR, the submit buttons should be disabled, the users post should be posted first, and a loading visualizer letting them know that their post is being analyzed or that the LLM is responding.