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

wolframalpha example #1

Merged
merged 4 commits into from
May 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bin/search_wolframalpha
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -e

# @describe Get an answer to a question using Wolfram Alpha. Input should the the query in English.
Copy link
Owner

Choose a reason for hiding this comment

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

Input should the the query in English.

Why did you specifically point it out? Is it really only possible to use English?

Copy link
Contributor Author

@gilcu3 gilcu3 May 16, 2024

Choose a reason for hiding this comment

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

I think that is the case, WolframAlpha natural language processing features are minimal as far I know.
PS: although the website now lists English, Spanish and Japanese

Copy link
Owner

@sigoden sigoden May 16, 2024

Choose a reason for hiding this comment

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

It's best not to limit. Each words occupies tokens.

If users use other languages and feel that the effect is not good, they will not use it, and there is no need to point it out here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those lines there actually make it useful for people using other languages. They are supposed to make the AI translate the query before passing it to WolframAlpha. I think a few words is a good price to pay for better accessibility.

Copy link
Owner

Choose a reason for hiding this comment

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

My understanding of this sentence is that search_wolframalpha only supports English. If you input other languages, it cannot be processed. Bye bye.
This does not tell LLM to translate into English.

Remove this sentence here, add more comments on --query

-- # @option --query! The query to search for.
++ # @option --query! The query to search for. Preferably in English.

Copy link
Contributor Author

@gilcu3 gilcu3 May 16, 2024

Choose a reason for hiding this comment

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

maybe, I am misunderstanding something then. What exactly is the input on the LLM when using functions? I thought it was the @describe text, not the @option text.

PS: I just tested my intuition and it seems to be correct. The LLM (at least the latest gpt-4o) translated a query in hungarian tényező a szám 12141124125125125 into
> call search_wolframalpha --query 'factor the number 12141124125125125' Yes.
Inputting the hungarian directly to WolframAlpha (website) gives nonsensical results.

Without that sentence therefore the AI may not translate anything and miss results.

PS2: Thinking about it more carefully, maybe the @describe field is used in 2 contexts, and those two are hard to conflate. It is what the user sees when figuring out what a function does, but it is also what the AI sees when trying to do the same.

Copy link
Owner

Choose a reason for hiding this comment

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

Since you've tested it, I'll defer to your judgment. Go ahead and fix the grammar, and I'm ready to merge.

-- Input should the the query in English.
++ Input should be the query in English.

# Use it to answer user questions that require computation, detailed facts, data analysis, or complex queries.
# This ensures accurate and precise answers.
# @option --query! The query to search for.
# @env WOLFRAM_API_KEY! The API key used to connect to WolframAlpha


main() {
local curl_args=(
-sSf -G
--data-urlencode "output=JSON"
--data-urlencode "format=plaintext"
--data-urlencode "input=$argc_query"
--data-urlencode "appid=$WOLFRAM_API_KEY"
"https://api.wolframalpha.com/v2/query"
)
curl "${curl_args[@]}" | jq -r '.queryresult.pods[] | select(.subpods[0].plaintext != "") | .title, .subpods[0].plaintext'
}

eval "$(argc --argc-eval "$0" "$@")"