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 cost estimation on text completion #38

Merged
merged 2 commits into from
Oct 4, 2023
Merged

Add cost estimation on text completion #38

merged 2 commits into from
Oct 4, 2023

Conversation

nicovank
Copy link
Contributor

@nicovank nicovank commented Oct 4, 2023

Warning
This depends on #37. Wish GitHub had some stacked diff capability.

% clang++ -std=c++20 tests/c++/missing-hash.cpp |& cwhy --llm gpt-4
The problem is that `std::hash` does not provide a specialization for
`std::pair<int, int>`. This means that you can't use `std::hash` with
`std::pair<int, int>`, hence the error. As a result, when you declare
an `std::unordered_set<std::pair<int, int>>`, the compiler is trying
to create an `std::hash<std::pair<int, int>>`, and failing because it
doesn't exist.

You could define a custom hash function for `std::pair<int, int>` and
use it in your `std::unordered_set`.

Here's an example:

```c++
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1, T2> &pair) const {
        return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
    }
};

std::unordered_set<std::pair<int, int>, pair_hash> visited;
```

In this code, `pair_hash` is a functor that computes a hash value for
`std::pair<int, int>` objects. This hash function is then used in the
`std::unordered_set` declaration.

This request cost ~ 0.12$.

@nicovank nicovank requested a review from emeryberger October 4, 2023 16:58
@emeryberger emeryberger merged commit 748368c into main Oct 4, 2023
5 checks passed
@nicovank nicovank deleted the cost branch October 4, 2023 20:11
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