Repository navigation
Expand file tree
/
Copy pathdemo_direct_gguf.cpp
More file actions
133 lines (101 loc) Β· 5.67 KB
/
Copy pathdemo_direct_gguf.cpp
File metadata and controls
133 lines (101 loc) Β· 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// demo_direct_gguf.cpp - Test direct GGUF file loading and inference
#include <iostream>
#include "include/bolt/ai/direct_gguf_inference.hpp"
#include "include/bolt/ai/enhanced_ai_manager.hpp"
using namespace bolt::ai; // NOLINT(build/namespaces)
void test_direct_inference() {
std::cout << "π§ͺ Testing Direct GGUF Inference" << std::endl;
std::cout << "=================================" << std::endl;
// Test auto-detection
auto direct_ai = DirectGGUFFactory::create_auto_detect();
if (direct_ai->is_loaded()) {
std::cout << "β
Model loaded successfully!" << std::endl;
std::cout << direct_ai->get_model_info() << std::endl;
// Test chat
std::cout << "\n㪠Testing chat..." << std::endl;
auto response = direct_ai->chat("Hello! Can you help me with C++ programming?");
std::cout << "AI Response: " << response.response << std::endl;
std::cout << "Success: " << (response.success ? "β
" : "β") << std::endl;
std::cout << "Time: " << response.inference_time_ms << "ms" << std::endl;
// Test code completion
std::cout << "\nπ§ Testing code completion..." << std::endl;
auto code_response = direct_ai->generate_text(
"Complete this C++ function:\nvoid quicksort(std::vector<int>& arr) {\n if (arr.size() <= 1) return;\n "
" // ",
100);
std::cout << "Code Completion: " << code_response.response << std::endl;
} else {
std::cout << "β οΈ No GGUF model loaded - testing fallback responses" << std::endl;
// Test fallback responses
auto response = direct_ai->chat("How do I use smart pointers in C++?");
std::cout << "Fallback Response: " << response.response << std::endl;
auto algorithm_response = direct_ai->chat("Explain binary search algorithm");
std::cout << "Algorithm Help: " << algorithm_response.response << std::endl;
auto config_response = direct_ai->chat("How do I configure AI models?");
std::cout << "Config Help: " << config_response.response << std::endl;
}
}
void test_enhanced_manager_with_gguf() {
std::cout << "\nπ Testing Enhanced AI Manager with GGUF" << std::endl;
std::cout << "=========================================" << std::endl;
EnhancedAIManager manager;
std::cout << "Manager ready: " << (manager.is_ready() ? "β
" : "β") << std::endl;
std::cout << "Current provider: " << manager.get_current_provider() << std::endl;
if (manager.has_direct_model()) {
std::cout << "π Model info: " << manager.get_model_info() << std::endl;
}
// Test chat functionality
std::cout << "\n㪠Testing chat with Enhanced Manager..." << std::endl;
auto chat_response = manager.chat("What are the benefits of using RAII in C++?", "test_session");
std::cout << "Chat Response: " << chat_response.response << std::endl;
std::cout << "Success: " << (chat_response.success ? "β
" : "β") << std::endl;
// Test session management
manager.create_session("cpp_help");
auto session_response = manager.chat("How do I properly manage memory in C++?", "cpp_help");
std::cout << "Session Response: " << session_response.response << std::endl;
// Show statistics
auto stats = manager.get_statistics();
std::cout << "\nπ AI Statistics:" << std::endl;
std::cout << " Total requests: " << stats.total_requests << std::endl;
std::cout << " Successful: " << stats.successful_requests << std::endl;
std::cout << " Failed: " << stats.failed_requests << std::endl;
std::cout << " Avg response time: " << stats.average_inference_time_ms << " ms" << std::endl;
}
void demonstrate_fallback_intelligence() {
std::cout << "\nπ§ Demonstrating Intelligent Fallback Responses" << std::endl;
std::cout << "===============================================" << std::endl;
DirectGGUFInference fallback_ai;
// Note: No model loaded, so it will use fallback responses
std::vector<std::string> test_questions = {
"How do I use std::unique_ptr?", "What's the difference between stack and heap?",
"Explain the quicksort algorithm", "How do I configure AI models?",
"What are C++ templates?", "Help me with STL containers"};
for (const auto& question : test_questions) {
std::cout << "\nQuestion: " << question << std::endl;
auto response = fallback_ai.chat(question);
std::cout << "Answer: " << response.response.substr(0, 200) << "..." << std::endl;
std::cout << "ββββββββββββββββββββββββββββββββββββ" << std::endl;
}
}
int main() {
std::cout << "π― Direct GGUF Loading and Inference Test" << std::endl;
std::cout << "=========================================" << std::endl;
try {
// Test 1: Direct inference engine
test_direct_inference();
// Test 2: Enhanced manager with GGUF integration
test_enhanced_manager_with_gguf();
// Test 3: Intelligent fallback responses
demonstrate_fallback_intelligence();
std::cout << "\nβ
Direct GGUF testing completed!" << std::endl;
std::cout << "\nπ‘ Next Steps:" << std::endl;
std::cout << "β’ Download a small GGUF model to test real AI inference" << std::endl;
std::cout << "β’ Try: wget https://huggingface.co/microsoft/DialoGPT-medium/resolve/main/model.gguf"
<< std::endl;
std::cout << "β’ Place in ./models/ directory and rerun this test" << std::endl;
} catch (const std::exception& e) {
std::cerr << "β Error during testing: " << e.what() << std::endl;
return 1;
}
return 0;
}