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

Request for Help: Show me queries that don't have a good answer #378

Open
gleitz opened this issue Apr 8, 2021 · 11 comments
Open

Request for Help: Show me queries that don't have a good answer #378

gleitz opened this issue Apr 8, 2021 · 11 comments

Comments

@gleitz
Copy link
Owner

gleitz commented Apr 8, 2021

howdoi needs your help! We're looking to improve the quality of answers returned by the system. If you find a query that doesn't seem to have the right answer, could you please include the query and the response below? We'll use this to build a robust set of heuristics and perhaps an AI model to help you hack better.

Here's an example:

» howdoi parse html regex
inal snuf

Instead, we should probably return the entire answer for this query.

Thanks!

@gleitz gleitz pinned this issue Apr 8, 2021
@gleitz
Copy link
Owner Author

gleitz commented Jul 13, 2021

Started collecting some bad queries and potential solutions at https://docs.google.com/spreadsheets/d/16nzBO6s4S61iScaEgtf6KAoJ5he7f3he5dJ-ElG9ViM/edit?usp=sharing

@gleitz
Copy link
Owner Author

gleitz commented Jul 13, 2021

We should update this line
https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.py#L353

To be smarter about how we pick the code block or answer. For example if there are multiple pre's then we should return all of them. If there is a code block but it's small we should perhaps return the entire answer, etc.

@theairbend3r
Copy link

The following gives the wrong answer.

$ python -m howdoi run for loop in python
#!/usr/bin/python

while True:
    # some python code that I want 
    # to keep on running

If I change the query slightly (delete the word "run"), I get correct answers.

$ python -m howdoi for loop in python
for k in range(1,c+1,2):
$ python -m howdoi for loop python
for k in range(1,c+1,2):

@V2dha
Copy link
Contributor

V2dha commented Dec 1, 2021

This query howdoi implement binary tree in C++ gives the following output instead of the actual implementation which is different from other languages also mentioned below -

In C++

$ howdoi implement binary tree in C++
root

The above answer returned is not the actual implementation whereas other languages usually return the full implementation even the uncommon languages.

In JavaScript

$ howdoi implement binary tree in javascript
function Node(value) {
    this.value = value;
    // this.left = null;
    // this.right = null;
}

function insertNode(tree, value) {
    var node = tree,
        key;
    while (node.value !== value) {
         key = value < node.value ? 'left' : 'right';
         if (!node) {
             node = new Node(value);
             break;
         }
         node = node;
    }
    return tree;
}

var array = [8, 10, 12, 5, 3, 6],
    tree = array.reduce((t, v) => t ? insertNode(t, v) : new Node(v), null);

console.log(tree);

In Go

$ howdoi implement binary tree in go
func InsertNodeToTree(tree *TreeNode, node *TreeNode) {
    if tree == nil {
        panic("cannot insert into nil root")
    }

    if node.Value > tree.Value {
        if tree.Right == nil {
            tree.Right = node
        } else {
            InsertNodeToTree(tree.Right, node)
        }
    }
    if node.Value < tree.Value {
        if tree.Left == nil {
            tree.Left = node
        } else {
            InsertNodeToTree(tree.Left, node)
        }
    }
}

Also while working on syntax highlighting, I noticed a lot of howdoi queries on C++ do not return an accurate answer. Following are some more examples -

$ howdoi implement linked list in C++
if(head == tail) {

$ howdoi implement stack in C++
cout<<"stack is emphty");

Furthermore, a lot of queries are based on C++ mentioned in this sheet

@justin-f-perez
Copy link
Contributor

justin-f-perez commented Dec 1, 2021

$ howdoi -ac check file exists bash --explain
INFO: Version: 2.0.19
INFO: Fetching answers for query: check file exists bash
INFO: Searching google with URL: https://www.google.com/search?q=site:stackoverflow.com%20check%20file%20exists%20bash&hl=en
INFO: Links from stackoverflow.com found on google: 1
INFO: URL: https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash
INFO: Answers requested: 1, Starting at position: 1
INFO: Total answers returned: 0

The answer to this query is in a code block in the top (accepted) answer of the SO link shown in the INFO: URL: line so its not clear why 0 answers would be returned

@gleitz
Copy link
Owner Author

gleitz commented Dec 3, 2021

@justin-f-perez would you try passing the -C flag to clear your cache? I do get a result when I try the same search:

» howdoi -ac check file exists bash --explain -C
INFO: Version: 2.0.19
Cache cleared successfully
INFO: Fetching answers for query: check file exists bash
INFO: Searching google with URL: https://www.google.com/search?q=site:stackoverflow.com%20check%20file%20exists%20bash&hl=en
INFO: Links from stackoverflow.com found on google: 1
INFO: URL: https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash
INFO: Answers requested: 1, Starting at position: 1
INFO: Total answers returned: 1
★  Answer from https://stackoverflow.com/questions/638975/how-do-i-tell-if-a-regular-file-does-not-exist-in-bash ★
The [test](http://man7.org/linux/man-pages/man1/test.1.html) command ([ here) has a "not" logical operator which is the exclamation point (similar to many other languages). Try this:
if [ ! -f /tmp/foo.txt ]; then
    echo "File not found!"
fi

@justin-f-perez
Copy link
Contributor

@gleitz This seems to be a pretty complex problem. Clearing cache didn't help.

My 'normal' howdoi installation is via pipx install howdoi (where pipx is installed via homebrew), which makes it globally available (installing to ~/.local/bin/howdoi) even if I have a python3-venv/conda-env activated. Additionally, I have two different versions of python installed via homebrew. The "default" is 3.9.9; however, pipx links new packages against python3.10.

I get the same result as you when I install:

  • via pip in a python3-venv on linux
  • via pipx inside of docker (image: python:3.10)
  • via pip inside of a conda environment

I also get "no answer" if I try to pipx run ... as well:

$ pipx run howdoi -ac check file exists bash --explain -C
INFO: Version: 2.0.19
Cache cleared successfully
...
ERROR: Sorry, couldn't find any help with that topic%

so I created a conda environment, pip installed howdoi (which returns an answer as expected) and diffed what was installed:

$ diff =(pipx runpip howdoi list) =(pip list)
5c5
> certifi            2020.6.20
---
< certifi            2021.10.8
7c7
> charset-normalizer 2.0.9
---
< charset-normalizer 2.0.8
23c23
> setuptools         58.0.4
---
< setuptools         59.4.0

Then I littered some print(f"{SOME_VARIABLE=}") around the code until I found where the behavior diverged between both environments- which turns out to be in _get_answer()

    print(f"{page=}")
    html = pq(page)
    print(f'{html=}')

    first_answer = html('.answercell').eq(0) or html('.answer').eq(0)
    print(f'{first_answer=}')

The content of page was identical for both; yet, pyquery (which has an identical version number in both environments) is parsing them differently in the pipx environment.
> good vs < bad

< html=[<html>]
---
> html=[<html.html__responsive.>]
< first_answer=[]
---
> first_answer=[<div.answercell.post-layout--right>]

So, I created a new vanilla python3-venv (python3 -m venv tmp-venv && source tmp-venv/bin/activate && pip install ...) and pip installed the frozen requirements from both the pipx and the conda environment. These both got no answer. I tried two more virtual environments from python3.9 and python3.10 installed via homebrew. Same deal.

$ /path/to/brew/bin/python3.10 -m venv ./tmp-venv
$ source tmp-venv/bin/activate
$ pip install howdoi
$ howdoi -ac check file exists bash --explain -C
Error...

I tried getting in there with pdb, but the misbehaving code runs in a multiprocessing pool.

@gleitz
Copy link
Owner Author

gleitz commented Dec 7, 2021

Wow that's wild. Thanks for the in-depth exploration. The hypothesis is that there is something about pipx that is preventing pages from being parsed correctly with pyquery.

I wonder if you could use this solution to get pdb in a multiprocessing thread:

https://stackoverflow.com/a/23654936/305414

@justin-f-perez
Copy link
Contributor

@gleitz thanks for the suggestion! will try when I have time (finals death-march season...)

I thought it was pipx at first too- then I thought it was python3.10 related. Now I suspect the problem is somehow related to homebrew's distribution of python3. That would explain why python3 -m venv style environments, pipx environments, and conda environments that don't specify a python (defaulting to "system python") all fail.

In other words...

< conda env create -n howdoi  # uses first python3 it finds on $PATH
> conda env create -n howdoi python=3.9 # conda installs its own interpreter
conda activate howdoi
pip install howdoi
howdoi -ac check file exists bash --explain -C
< ERROR
> answer
env style python source works?
conda, python=unspecified homebrew
pipx run homebrew
pipx install homebrew
python3.9 -m venv homebrew
python3.10 -m venv homebrew
docker run python:3.9 apt
python3 -m venv (bare metal linux) apt
conda, python=3.9 conda
conda, python=3.10 conda

@ghost
Copy link

ghost commented Mar 13, 2022

Running howdoi reverse a binary tree in typescript gives this result:

class Demo {
    overload(a) {
        console.log('hi');
    }
    overload() {
        console.log('bye');
    }
    overload(a, b) {
        console.log('wow');
    }
}

const d = new Demo();
d.overload();
d.overload(1);
d.overload(1, 2);

Which first, doesn't use TypeScript, and second, doesn't reverse a binary tree. (Atleast it doesn't look like it, I haven't executed the code.)

On the topic of binary trees and TypeScript, running howdoi implement binary tree in typescript gives an incomplete answer:

interface TreeNode<T> {
    left?: TreeNode<T>;
    right?: TreeNode<T>;
    data: T;
}

(thats it)
Actually, now that I think about it, it might not be so incomplete.

Running howdoi use for loop in javascript (with the use!) gives this result:

person[name] = 'Tom'

@gleitz
Copy link
Owner Author

gleitz commented Nov 12, 2022

howdoi reverse a binary tree in typescript

Turns out this now gives a (more) correct answer, that is also in Typescript. Kudos to the community for ranking answers and linking to them which raises their search ranking.

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

No branches or pull requests

4 participants