plasma-umass / cwhy

"See why!" Explains and suggests fixes for compile-time errors for C, C++, C#, Go, Java, LaTeX, PHP, Python, Ruby, Rust, and TypeScript
Apache License 2.0
272 stars 6 forks source link

Add new conversation mode: beginning a back-and-forth GPT mode #48

Closed nicovank closed 9 months ago

nicovank commented 9 months ago

This is a start to have a back-and-forth mode with ChatGPT. The assistant should be able to call functions and ask information to CWhy to provide a better diagnostic.

So far I've only been able to get it to call a single function, example below.

% g++ -c tests/c++/push-back-pointer.cpp |& cwhy --llm gpt-4 converse
Calling: get_code_surrounding(filename=tests/c++/push-back-pointer.cpp, lineno=24)
The error says that there's no matching function for call to `push_back(int*&)`,
and it's occurring because you're trying to push an `int*` (integer pointer)
into a `std::vector<int>` (vector of integers). The `push_back` method of
`std::vector` is expecting an `int` (since your vector is of type `int`), but
you're providing an `int*`.

To resolve this issue, you should dereference the pointer when pushing it to the
vector. This way, you're pushing the integer value the pointer is pointing to,
rather than the pointer itself.

Here's the corrected code:

```cpp
#include <vector>

int main() {
    std::vector<int> v;
    int value = 10;
    int* pointer = &value;
    v.push_back(*pointer);
}

In this code, *pointer dereferences the pointer, meaning it gets the integer value the pointer is pointing to. The push_back method now receives an int, which matches its expected argument type.



A single function is provided, `get_compile_or_run_command`, but more can be added. For example, I think the wrapper mode should be default (completely remove non-wrapper mode), and we could then easily provide the compile/run command. The error message (truncated) is passed as the user prompt, we could also provide a way to access more parts of it.

PS: A similar system might be of even bigger interest in ChatDBG.
emeryberger commented 9 months ago

Agreed on wrapper mode only and on the ChatDBG use case.