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

Add Web Search capabilities #20

Merged
merged 12 commits into from
May 19, 2024
Merged

Add Web Search capabilities #20

merged 12 commits into from
May 19, 2024

Conversation

XInTheDark
Copy link
Owner

@XInTheDark XInTheDark commented May 15, 2024

Adds basic Web Search capability that can be enabled in Preferences. Currently only available in AI Chat, will consider implementing into other AI commands later. Currently more testing of this feature needs to be done.

Summary: When the user sends a message, the AI decides for itself whether to run a web search. The system prompt is used to instruct the AI that it should request a web search only when it is strongly relevant to the user query.

Searches are done using the Tavily API; an API Key needs to be provided in Preferences, and for the free plan there is a limit of 1000 requests/month.

Also included: many many refactors.

closes #19

@XInTheDark XInTheDark marked this pull request as draft May 15, 2024 15:09
Copy link

Qodana for JS

2 new problems were found

Inspection name Severity Problems
Unused local symbol 🔶 Warning 2

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Detected 65 dependencies

Third-party software list

This page lists the third-party software dependencies used in project

Dependency Version Licenses
@raycast/api 1.71.3 MIT
@raycast/utils 1.14.0 MIT
@types/node 20.12.7 MIT
@types/prop-types 15.7.12 MIT
@types/react 18.2.78 MIT
@types/signale 1.4.7 MIT
ansi-styles 3.2.1 MIT
asynckit 0.4.0 MIT
axios 1.6.8 MIT
chalk 2.4.2 MIT
color-convert 1.9.3 MIT
color-name 1.1.3 MIT
combined-stream 1.0.8 MIT
content-type 1.0.5 MIT
cross-fetch 3.1.8 MIT
csstype 3.1.3 MIT
delayed-stream 1.0.0 MIT
dequal 2.0.3 MIT
encoding 0.1.13 MIT-0
error-ex 1.3.2 MIT
escape-string-regexp 1.0.5 MIT
figures 2.0.0 MIT
find-up 2.1.0 MIT
follow-redirects 1.15.6 MIT
form-data 4.0.0 MIT
g4f 1.4.3 GPL-3.0-only
gemini-ai 1.1.0 GPL-3.0-only
graceful-fs 4.2.11 ISC
has-flag 3.0.0 MIT
iconv-lite 0.6.3 MIT
is-arrayish 0.2.1 MIT
is-stream 1.1.0 MIT
js-tokens 4.0.0 MIT
json-parse-better-errors 1.0.2 MIT
load-json-file 4.0.0 MIT
locate-path 2.0.0 MIT
loose-envify 1.4.0 MIT
media-typer 1.1.0 MIT
mime-db 1.52.0 MIT
mime-types 2.1.35 MIT
node-fetch-polyfill 2.0.6 MIT
node-fetch 2.7.0 MIT
node-web-streams 0.2.2 Apache-2.0
object-hash 3.0.0 MIT
p-limit 1.3.0 MIT
p-locate 2.0.0 MIT
p-try 1.0.0 MIT
parse-json 4.0.0 MIT
path-exists 3.0.0 MIT
pify 3.0.0 MIT
pkg-conf 2.1.0 MIT
proxy-from-env 1.1.0 MIT
react 18.2.0 MIT
safer-buffer 2.1.2 MIT
signal-exit 4.1.0 ISC
signale 1.4.0 MIT
stream-chain 2.2.5 BSD-3-Clause
stream-json 1.8.0 BSD-3-Clause-Clear
strip-bom 3.0.0 MIT
supports-color 5.5.0 MIT
tr46 0.0.3 MIT
undici-types 5.26.5 MIT
web-streams-polyfill 1.2.2 MIT
webidl-conversions 3.0.1 BSD-2-Clause
whatwg-url 5.0.0 MIT
Contact Qodana team

Contact us at [email protected]

@XInTheDark
Copy link
Owner Author

also todo: change visibility of messages such that we have an optimal user experience: user enters query, the search web part is done in the backend, then the correct response is directly returned within the same message. currently we have 2 messages in between as shown:

message 1.
user: enters query
gpt: requests web search

message 2.
"user" (impersonated by system): returns web search results
"gpt": null

message 3.
"user" (impersonated by system): query is repeated.
gpt: provides response.

But what we can do is after requesting the web search, directly modify the messages history such that the web search results are appended at the end of the user message. Then, we erase the part where gpt requests web search, because that's not useful.

message 1.
user: enters query
gpt: requests web search
[Directly after we get the web search results here, we modify the chat history to 1) remove the gpt message and 2) append web result at end of user message. Then we regenerate response.]

new chat history look like this
message 1.
user: enters query + web search results
gpt: gives response
perfect.

@XInTheDark
Copy link
Owner Author

XInTheDark commented May 15, 2024

this also means we can completely remove visible parameter. it would expose web search results in the conversation, which is admittedly not very nice visually, but we can work on that later

edit: no, the system prompt still has to be invisible

Copy link

github-actions bot commented May 17, 2024

Qodana for JS

5 new problems were found

Inspection name Severity Problems
ESLint 🔶 Warning 2
Unused local symbol 🔶 Warning 2
Unnecessary 'return' statement 🔶 Warning 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Detected 65 dependencies

Third-party software list

This page lists the third-party software dependencies used in project

Dependency Version Licenses
@raycast/api 1.71.3 MIT
@raycast/utils 1.14.0 MIT
@types/node 20.12.7 MIT
@types/prop-types 15.7.12 MIT
@types/react 18.2.78 MIT
@types/signale 1.4.7 MIT
ansi-styles 3.2.1 MIT
asynckit 0.4.0 MIT
axios 1.6.8 MIT
chalk 2.4.2 MIT
color-convert 1.9.3 MIT
color-name 1.1.3 MIT
combined-stream 1.0.8 MIT
content-type 1.0.5 MIT
cross-fetch 3.1.8 MIT
csstype 3.1.3 MIT
delayed-stream 1.0.0 MIT
dequal 2.0.3 MIT
encoding 0.1.13 MIT-0
error-ex 1.3.2 MIT
escape-string-regexp 1.0.5 MIT
figures 2.0.0 MIT
find-up 2.1.0 MIT
follow-redirects 1.15.6 MIT
form-data 4.0.0 MIT
g4f 1.4.3 GPL-3.0-only
gemini-ai 1.1.0 GPL-3.0-only
graceful-fs 4.2.11 ISC
has-flag 3.0.0 MIT
iconv-lite 0.6.3 MIT
is-arrayish 0.2.1 MIT
is-stream 1.1.0 MIT
js-tokens 4.0.0 MIT
json-parse-better-errors 1.0.2 MIT
load-json-file 4.0.0 MIT
locate-path 2.0.0 MIT
loose-envify 1.4.0 MIT
media-typer 1.1.0 MIT
mime-db 1.52.0 MIT
mime-types 2.1.35 MIT
node-fetch-polyfill 2.0.6 MIT
node-fetch 2.7.0 MIT
node-web-streams 0.2.2 Apache-2.0
object-hash 3.0.0 MIT
p-limit 1.3.0 MIT
p-locate 2.0.0 MIT
p-try 1.0.0 MIT
parse-json 4.0.0 MIT
path-exists 3.0.0 MIT
pify 3.0.0 MIT
pkg-conf 2.1.0 MIT
proxy-from-env 1.1.0 MIT
react 18.2.0 MIT
safer-buffer 2.1.2 MIT
signal-exit 4.1.0 ISC
signale 1.4.0 MIT
stream-chain 2.2.5 BSD-3-Clause
stream-json 1.8.0 BSD-3-Clause-Clear
strip-bom 3.0.0 MIT
supports-color 5.5.0 MIT
tr46 0.0.3 MIT
undici-types 5.26.5 MIT
web-streams-polyfill 1.2.2 MIT
webidl-conversions 3.0.1 BSD-2-Clause
whatwg-url 5.0.0 MIT
Contact Qodana team

Contact us at [email protected]

@XInTheDark XInTheDark marked this pull request as ready for review May 17, 2024 12:25
1. Fix for duplicate user messages

A redundant query parameter was passed.

Logging in the console produces

Old version:
{ role: 'user', content: 'hi' }
{ role: 'user', content: 'hi' }

New version:
 { role: 'user', content: 'hi' }

2. Fix retrying generation for deepInfra and replicate

Incorrect parameter was passed, following a parameter change from `model` to `options`.

3. Fix regenerate last message.
Similar to bug 1, incorrect logic was used regarding passing `query` parameter.
@XInTheDark
Copy link
Owner Author

lgtm in dev build

@XInTheDark
Copy link
Owner Author

casual testing so far has been fine.

for future reference we also have another alternative: run a search for literally anything. while easily implementable,

  1. this reduces the effective context length by a lot because we append search results to end of every query
  2. the API rate limit gets used pretty quickly; haven't found a good unlimited API so far

@XInTheDark XInTheDark merged commit ca255ab into main May 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Web Search capabilities
1 participant