-
Notifications
You must be signed in to change notification settings - Fork 45
feat: enhance AI JSON response with sources, confidence, and tags #141
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include "metadata.hpp" | ||
|
|
||
| using json = nlohmann::json; | ||
|
|
||
| json extractSources(const std::string& text) { | ||
| json sources = json::array(); | ||
|
|
||
| if (text.find("ST_") != std::string::npos) { | ||
| sources.push_back({ | ||
| {"title", "PostGIS Documentation"}, | ||
| {"url", "https://postgis.net/docs/"}}); | ||
| } | ||
|
|
||
| if (text.find("SELECT") != std::string::npos) { | ||
| sources.push_back({ | ||
| {"title", "PostgreSQL SELECT"}, | ||
| {"url", "https://www.postgresql.org/docs/current/sql-select.html"}}); | ||
| } | ||
|
|
||
| return sources; | ||
| } | ||
|
|
||
| double calculateConfidence(const std::string& text) { | ||
| if (text.length() > 150) return 0.9; | ||
| if (text.length() > 50) return 0.75; | ||
| return 0.6; | ||
| } | ||
|
Comment on lines
+23
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this calculate ai confidence query ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question ... currently the confidence score is a simple heuristic, not derived from the AI model itself. Right now it’s based on the length of the generated explanation:
This is just an initial placeholder to provide a basic signal to users. In future iterations, this could be improved by:
Happy to refine this approach based on suggestions. |
||
|
|
||
| json extractTags(const std::string& text) { | ||
| json tags = json::array(); | ||
|
|
||
| if (text.find("ST_") != std::string::npos) | ||
| tags.push_back("postgis"); | ||
|
|
||
| if (text.find("JOIN") != std::string::npos) | ||
| tags.push_back("join"); | ||
|
|
||
| if (text.find("INDEX") != std::string::npos) | ||
| tags.push_back("performance"); | ||
|
|
||
| return tags; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
| #include <string> | ||
| #include <nlohmann/json.hpp> | ||
|
|
||
| nlohmann::json extractSources(const std::string& text); | ||
| double calculateConfidence(const std::string& text); | ||
| nlohmann::json extractTags(const std::string& text); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include <cassert> | ||
| #include "/home/lucifer/Desktop/pg_ai_query/src/core/metadata.hpp" | ||
|
|
||
| int main() { | ||
| std::string text = "Use ST_Distance in PostGIS"; | ||
|
|
||
| auto sources = extractSources(text); | ||
| assert(!sources.empty()); | ||
|
|
||
| double conf = calculateConfidence(text); | ||
| assert(conf > 0); | ||
|
|
||
| auto tags = extractTags(text); | ||
| assert(!tags.empty()); | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you only cover select and Postgis queries for documentation, i don't think this should be done this way