Skip to content

webui : add ?m=... and ?q=... params #12148

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

Merged
merged 5 commits into from
Mar 3, 2025

Conversation

ngxson
Copy link
Collaborator

@ngxson ngxson commented Mar 2, 2025

Supersede #11150

  • If the current URL contains "?m=...", prefill the message input with the value.
  • If the current URL contains "?q=...", prefill and SEND the message. ("q" means query, this param used by search engines like google.com/?q=test or chatgpt.com/?q=test)

Example:

  • http://localhost:8080/?m=Translate%20to%20French:%20 (then user need to fill the rest)
  • http://localhost:8080/?q=What%20is%20llama

CC @tim-janik

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR implements URL query parameter handling to prefill the chat input and optionally auto-send messages based on the parameters "?m=..." and "?q=...".

  • Added a utility (cleanCurrentUrl) to remove query parameters from the URL.
  • Updated ChatScreen to extract query parameters and set or send the prefilled message accordingly.

Reviewed Changes

File Description
examples/server/webui/src/utils/misc.ts Added cleanCurrentUrl function to clear specified query parameters from the current URL.
examples/server/webui/src/components/ChatScreen.tsx Introduced query parameter extraction to prefill and optionally send messages, and updated initial state for the message input.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@ngxson ngxson requested a review from Copilot March 2, 2025 17:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR introduces functionality to prefill and optionally auto-send messages via query parameters in the web UI. Key changes include:

  • Adding a helper function (cleanCurrentUrl) to remove specified query parameters from the URL.
  • Implementing logic to prefill the message input with the value from the URL parameter.
  • Automatically sending a message if a certain query parameter is detected.

Reviewed Changes

File Description
examples/server/webui/src/utils/misc.ts Added a utility function to clean query parameters from the URL
examples/server/webui/src/components/ChatScreen.tsx Prefills the message input and optionally triggers auto-send on load

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@ngxson ngxson requested a review from Copilot March 2, 2025 17:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request introduces URL query parameter handling to prefill the chat message input and trigger message sending automatically based on the presence of specific query parameters. The changes include:

  • Adding a new utility function (cleanCurrentUrl) to remove specified query parameters from the URL.
  • Implementing a prefill mechanism in ChatScreen.tsx that reads the URL for parameters ?m and ?q.
  • Triggering automatic message sending when ?q is detected, along with input focus management.

Reviewed Changes

File Description
examples/server/webui/src/utils/misc.ts Added cleanCurrentUrl() to remove specific query parameters from the URL.
examples/server/webui/src/components/ChatScreen.tsx Updated to prefill the message input and conditionally trigger automatic message sending based on URL parameters.

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

examples/server/webui/src/components/ChatScreen.tsx:206

  • Using sendNewMessage inside the useEffect without including it (or wrapping it with useCallback) in the dependency array may lead to unexpected behavior if its definition changes. Consider refactoring sendNewMessage to be memoized or adding it to the dependency array.
    // eslint-disable-next-line react-hooks/exhaustive-deps

@github-actions github-actions bot added the python python script changes label Mar 3, 2025
@ngxson
Copy link
Collaborator Author

ngxson commented Mar 3, 2025

The CI fails due to timeout, maybe there's an on-going problem on HF. Not related to changes in this PR, so I will merge this PR anw

@ngxson ngxson merged commit 7b69003 into ggml-org:master Mar 3, 2025
6 of 8 checks passed
poulphunter pushed a commit to poulphunter/llama.cpp_server_webui that referenced this pull request Mar 6, 2025
@tim-janik
Copy link

Supersede #11150

* If the current URL contains "?m=...", prefill the message input with the value.

* If the current URL contains "?q=...", prefill and SEND the message. ("q" means query, this param used by search engines like google.com/?q=test or chatgpt.com/?q=test)

Example:

* `http://localhost:8080/?m=Translate%20to%20French:%20` (then user need to fill the rest)

* `http://localhost:8080/?q=What%20is%20llama`

CC @tim-janik

Thanks for carrying this over to the React UI implementation.
I have just build master and tested ?q and ?m and both seem to work fine as in the original PR.
Except that the URL is cleared right after loading.
That makes it a bit harder for users to edit+construct new URLs, is that intentional or not technically feasible otherwise?

mglambda pushed a commit to mglambda/llama.cpp that referenced this pull request Mar 8, 2025
* webui : add ?m=... and ?q=... params

* also clear prefilledMessage variable

* better approach

* fix comment

* test: bump timeout on GITHUB_ACTION
arthw pushed a commit to arthw/llama.cpp that referenced this pull request Mar 19, 2025
* webui : add ?m=... and ?q=... params

* also clear prefilledMessage variable

* better approach

* fix comment

* test: bump timeout on GITHUB_ACTION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples python python script changes server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants