Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace {{current_date}} server side for OpenAI, Anthropic and Assistants #4335

Closed
wants to merge 35 commits into from

Conversation

owengo
Copy link

@owengo owengo commented Oct 4, 2024

Pull Request Template

⚠️ Before Submitting a PR, Please Review:

  • Please ensure that you have thoroughly read and understood the Contributing Docs before submitting your Pull Request.

⚠️ Documentation Updates Notice:

  • Kindly note that documentation updates are managed in this repository: librechat.ai

LibreChat-AI/librechat.ai#132

Summary

Following discussion at: #3713

This is a proposal to replace a special variable: {{current_date}} in the system prompt ( for OpenAI et Anthropic ) or the "extended instructions" of the Assistants. Could be extended to other models too.

Change Type

Please delete any irrelevant options.

  • New feature (non-breaking change which adds functionality)

Testing

Please describe your test process and include instructions so that we can reproduce your test. If there are any important variables for your testing configuration, list them here.

Create a custom setting like this for OpenAI or Anthropic:
"Your are a helpful assistant. Today is the {{current_date}}"

Then, using this setting, ask "What day is it today?"
The bot should give the correct answer ( based on the server settings ).

Test Configuration:

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • Local unit tests pass with my changes
  • A pull request for updating the documentation has been submitted.

owengo and others added 27 commits October 7, 2024 10:54
remove debug log
API query for OpenAI returns list of models. Their names are filtered using a regex. The regex did not yet account for model names starting with o1-
…#4390)

* chore: cleanup type issues in client/src/utils/endpoints

* refactor: use Constant enum for 'new' conversationId

* refactor: select assistant model if not provided for model spec
* refactor: add 5 second timeout for fetching AI provider model lists

* ci: fix test due to recent changes
* chore: bump cookie dependencies

* chore: bump express, express-session, express-rate-limit, and all vulnerable `cookie` dependencies
…a#4433)

* refactor: move file mutations to dedicated file, improve typing

* refactor(ChatForm): utilize FileFormWrapper to consolidate file upload logic/rendering to single parent

* refactor: better TSX heirarchies between AttachFile and FileFormWrapper

* refactor: `abortUpload` WIP

* fix: file debugging and file upload issues

* refactor: reject promise outright if axios intercepted error does not include response property

* chore: bump data-provider version to 0.7.428

* refactor: Add return type to localize function in Translation.ts

* refactor: allow message file attachment upload request cancellations, and add localizations for file upload errors

* refactor: include Azure OpenAI in paramEndpoints set

* fix: assistant form uploads and better typing

* refactor: consolidate logic
* refactor(OpenAIClient): titleChatCompletion try/catch

* fix: remove duplicate concatenation as seems to be handled by client SDK now

* fix: assistants image upload

* chore: imports order
* feat: Refactor ChatForm and StopButton components for improved styling and localization

* feat: Refactor AudioRecorder, ChatForm, AttachFile, and SendButton components for improved styling and layout

* feat: Add RevokeAllKeys component and update styling for buttons and inputs

* feat: Refactor ClearChats component and update ClearConvos functionality for improved clarity and user experience

* feat: Remove ClearConvos component and update related imports and functionality in Avatar and DeleteCacheButton components

* feat: Rename DeleteCacheButton to DeleteCache and update related imports; enhance confirmation message in localization

* feat: Update ChatForm layout for RTL support and improve component structure

* feat: Adjust ChatForm layout for improved RTL support and alignment

* feat: Refactor Bookmark components to use new UI elements and improve styling

* feat: Update FileSearch and ShareAgent components for improved button styling and layout

* feat: Update ChatForm and TextareaHeader styles for improved UI consistency

* feat: Refactor Nav components for improved styling and layout adjustments

* feat: Update button sizes and padding for improved UI consistency across chat components

* feat: Remove ClearChatsButton test file as part of code cleanup
…and Layout (danny-avila#4471)

* 🎨 style: adjust padding and class names in UI components

* 🎨 style: update ExportModal export button, update Export button hover style, refactor ChatForm style and fixed isRTL styles, update AttachFile position

* 🎨 style: remove redundant border classes in SettingsTabs components for cleaner UI

* 🎨 style: refactor Account component, extract DisplayUsernameMessages, and remove redundant border classes for cleaner layout

* 🎨 style: conditionally render Dropdown in ForkSettings component for improved UI responsiveness

* 🎨 style: replace DropdownNoState with Dropdown in voice selection components for consistency

* 🎨 style: update Settings component layout for better responsivenes on large screens

* 🎨 style: remove redundant margin-top classes for cleaner layout in various components
* fix(Agents): remove test code in openAI/llm.js

* refactor: add use of enums in encodeAndFormat

* fix: image attachment payload formatting for agents

* chore: imports
The changes include:
- In the agent controller:
  - Removed the parsing of the avatar metadata from the request body.
  - Fetched the avatar data from the agent object using the agent ID.
  - Updated the error logging when fetching the agent.
  - Updated the deleteFileByFilter function to include the user ID when deleting the old avatar file.

- In the assistant controller:
  - Removed the parsing of the metadata from the request body.
  - Fetched the metadata from the assistant object using the assistant ID.
  - Updated the error logging when fetching the assistant.
  - Updated the deleteFileByFilter function to include the user ID when deleting the old avatar file.
…4529)

* fix: vision prompt error handling

* fix: Update model reference in chatV1 controller

* remove model reference
…a#4536)

* 🔘 a11y: Improve Contrast of Switch/Toggles to WCAG Standard

* refactor: Improve file attachment accessibility in Chat Input component

* refactor: clear input ref value before clicks
danny-avila and others added 6 commits October 25, 2024 14:32
* fix: Update useTextarea to handle Ctrl+Enter on Mac

* fix: Update language files for message sending behavior
…Zh) (danny-avila#4540)

* chore: remove comparisons

* feat: use prompt caching for translations

* chore: wip translation readme

* i18n: korean translations

* refactor: use promises for faster translation processing

* refactor: update translation model to 'claude-3-5-sonnet-20241022'

* refactor: optimize sleep duration for translation processing

* i18n: add missing keys

* refactor: standardize languages in their own respective languages

* Refactor translation instructions in README.md
* fix: ReDoS in ChatGPT Import

* ci: should correctly process citations from real ChatGPT data

* ci: Add ReDoS vulnerability test for processAssistantMessage

* refactor: Update thread management and citation handling

* refactor(validateImageRequest): robust validation

* refactor(Prompt.js): update name search regex to escape special characters

* refactor(Preset): exclude user from preset update to prevent mass assignment

* refactor(files.js): Improve file deletion process

* ci: updated validateImageRequest.spec.js

* a11y: plugin pagination

* refactor(CreatePromptForm.tsx): Improve input field styling

* chore(Prompts): typing and accessibility

* fix: prompt creation access role check

* chore: remove duplicate jsdocs
@danny-avila
Copy link
Owner

When making a PR, there's no need to keep your branch updated to latest unless the underlying files you changed were also changed. In which case, the git rebase strategy is preferred as it would put your commits on top of the latest changes

@danny-avila
Copy link
Owner

danny-avila commented Oct 25, 2024

I've closed this PR because there are too many irrelevant changes, created likely due to how the branch was updated.

Also for this feature, changes should take place in api/server/middleware/buildEndpointOption.js so it could affect every endpoint.

Lastly, I would prefer this feature be implemented in a way that allows the special variables to still be replaced client-side. The reason is that the time strings could be created relative to the user and not the server. maybe {{server_*}} prefix or something like that, for server-specific variables.

@owengo
Copy link
Author

owengo commented Oct 25, 2024

Oh sorry for the pr on the main branch, stupid mistake. I use the branch for other changes completely unrelated.
I agree that using the client timezone would be better, but I'm not sure how you want to keep it updated if it's done client-side.

Let's say you start a conversation today, and you go on with it next week, what do you send in the system prompt? today? last week? If it's today ( which was the behavior with the PR ) I'm not sure how the client side is supposed to override the system-prompt stored last week.
As I understand the code the client sends only the last message so we would need to add a client parameter like "current-client-side-date" and have it processed by the middleware.
Thanks for the middleware tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.