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 new conversation mode: beginning a back-and-forth GPT mode #48

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

nicovank
Copy link
Contributor

@nicovank nicovank commented Jan 9, 2024

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.

@nicovank nicovank merged commit ed45c1f into main Jan 9, 2024
5 checks passed
@nicovank nicovank deleted the conversation branch January 9, 2024 21:27
@emeryberger
Copy link
Member

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

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

Successfully merging this pull request may close these issues.

2 participants