danny-avila / LibreChat

Enhanced ChatGPT Clone: Features Anthropic, AWS, OpenAI, Assistants API, Azure, Groq, o1, GPT-4o, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, langchain, DALL-E-3, ChatGPT Plugins, OpenAI Functions, Secure Multi-User System, Presets, completely open-source for self-hosting. Actively in public development.
https://librechat.ai/
MIT License
17.86k stars 2.96k forks source link

refactor: move shared conditions and early bail #3204

Closed rehas closed 3 months ago

rehas commented 3 months ago

Summary

To reduce cognitive complexity and improve readability, we can move the common conditionals to the early phase and bail.

Change Type

Testing

npm run test:client
Test Suites: 27 passed, 27 total
Tests:       116 passed, 116 total
Snapshots:   0 total
Time:        123.37 s

Test Configuration:

Checklist

Please delete any irrelevant options.

danny-avila commented 3 months ago

This is tricky because this is an important part of the app. I've been burned by || conditions and I'm hesistant to accept as is. I will re-submit a better version of this. Also, I would like to discourage PRs like this where the benefit is not weighty enough to merit an effort. Best to follow the old axiom "if it ain't broke, don't fix it"

Also the tests don't have a case for what the effect is doing in this case, but there should be a test as it's important.