Skip to content

Commit 2eae9d8

Browse files
authored
Merge pull request #28 from jmont-dev/cleanup
Clean up warnings and unused parameters.
2 parents 57bd8fe + 717966d commit 2eae9d8

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

Diff for: Makefile

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
# Check if a default C++ compiler exists, otherwise use g++
22
CXX ?= g++
3+
CXXFLAGS = -Wall -Wextra -Wpedantic
4+
5+
CREATE_BUILD_DIR = mkdir -p build; cp -n llama.jpg build;
36

47
all: examples test-cpp11 test-cpp14 test-cpp20
5-
examples: examples/main.cpp
8+
build:
69
mkdir -p build
7-
$(CXX) examples/main.cpp -Iinclude -o build/examples -std=c++11 -pthread -latomic
10+
ifeq ($(OS),Windows_NT)
11+
if not exist "build/llama.jpg" copy "llama.jpg" "build"
12+
else
13+
cp -n llama.jpg build
14+
endif
15+
examples: build examples/main.cpp
16+
$(CXX) $(CXXFLAGS) examples/main.cpp -Iinclude -o build/examples -std=c++11 -pthread -latomic
817
test: test-cpp11
9-
test-cpp11: test/test.cpp
10-
mkdir -p build
11-
$(CXX) test/test.cpp -Iinclude -Itest -o build/test -std=c++11 -pthread -latomic
12-
test-cpp14: test/test.cpp
13-
mkdir -p build
14-
$(CXX) test/test.cpp -Iinclude -Itest -o build/test-cpp14 -std=c++14 -pthread -latomic
15-
test-cpp20: test/test.cpp
16-
mkdir -p build
17-
$(CXX) test/test.cpp -Iinclude -Itest -o build/test-cpp20 -std=c++2a -pthread -latomic
18+
test-cpp11: build test/test.cpp
19+
$(CXX) $(CXXFLAGS) test/test.cpp -Iinclude -Itest -o build/test -std=c++11 -pthread -latomic
20+
test-cpp14: build test/test.cpp
21+
$(CXX) $(CXXFLAGS) test/test.cpp -Iinclude -Itest -o build/test-cpp14 -std=c++14 -pthread -latomic
22+
test-cpp20: build test/test.cpp
23+
$(CXX) $(CXXFLAGS) test/test.cpp -Iinclude -Itest -o build/test-cpp20 -std=c++2a -pthread -latomic
1824
clean:
1925
rm -rf build

Diff for: examples/main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int main()
6262

6363
// Create a blob on the ollama server using the following digest
6464
try { ollama::create_blob("sha256:29fdb92e57cf0827ded04ae6461b5931d01fa595843f55d36f5b275a52087dd2"); std::cout << "Blob was created on Ollama server." << std::endl; }
65-
catch( ollama::exception e) { std::cout << "Error when creating blob: " << e.what() << std::endl;}
65+
catch( ollama::exception& e) { std::cout << "Error when creating blob: " << e.what() << std::endl;}
6666

6767
// Check if a blob with the following digest exists.
6868
if ( ollama::blob_exists("sha256:29fdb92e57cf0827ded04ae6461b5931d01fa595843f55d36f5b275a52087dd2") ) std::cout << "Blob exists on Ollama server." << std::endl;
@@ -95,7 +95,7 @@ int main()
9595
try {
9696
ollama::generate("Non-existent-model", "Requesting this model will throw an error");
9797
}
98-
catch(ollama::exception e) { std::cout << e.what() << std::endl; }
98+
catch(ollama::exception& e) { std::cout << e.what() << std::endl; }
9999

100100
//Alternatively, throwing exceptions can be disabled. In this case, either emptry values or false will be returned in the event of an error.
101101
//ollama::allow_exceptions(false);
@@ -117,6 +117,7 @@ int main()
117117
// Optionally send a request to ollama to load a model into memory.
118118
// This will occur automatically during generation but this allows you to preload a model before using it.
119119
bool model_loaded = ollama::load_model("llama3:8b");
120+
if (model_loaded) std::cout << "Model has been loaded";
120121

121122
// Perform a simple generation to a string by specifying a model and a prompt. The response will be returned as one string without streaming the reply.
122123
std::cout << ollama::generate("llama3:8b", "Why is the sky blue?") << std::endl;

Diff for: include/ollama.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace ollama
101101
public:
102102
image(const std::string base64_sequence, bool valid = true)
103103
{
104-
this->base64_sequence = base64_sequence;
104+
this->base64_sequence = base64_sequence; this->valid = valid;
105105
}
106106
~image(){};
107107

@@ -254,7 +254,7 @@ namespace ollama
254254
(*this)["stream"] = stream;
255255

256256
if (options!=nullptr) (*this)["options"] = options["options"];
257-
//(*this)["format"] = format; // Commented out as providing the format causes issues with some models.
257+
(void)format; //(*this)["format"] = format; // Commented out as providing the format causes issues with some models.
258258
(*this)["keep_alive"] = keep_alive_duration;
259259
type = message_type::chat;
260260

@@ -329,7 +329,7 @@ namespace ollama
329329
return simple_string;
330330
}
331331

332-
const bool has_error() const
332+
bool has_error() const
333333
{
334334
if ( json_data.contains("error") ) return true;
335335
return false;
@@ -835,7 +835,6 @@ class Ollama
835835
std::string get_version()
836836
{
837837
std::string version;
838-
httplib::Client cli("http://localhost:11434");
839838

840839
auto res = this->cli->Get("/api/version");
841840

@@ -872,12 +871,13 @@ class Ollama
872871

873872
private:
874873

874+
/*
875875
bool send_request(const ollama::request& request, std::function<void(const ollama::response&)> on_receive_response=nullptr)
876876
{
877877
878878
return true;
879879
}
880-
880+
*/
881881

882882
std::string server_url;
883883
httplib::Client *cli;
@@ -1040,7 +1040,7 @@ namespace ollama
10401040
ollama.setWriteTimeout(seconds);
10411041
}
10421042

1043-
};
1043+
}
10441044

10451045

10461046
#endif

Diff for: singleheader/ollama.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -34891,7 +34891,7 @@ namespace ollama
3489134891
public:
3489234892
image(const std::string base64_sequence, bool valid = true)
3489334893
{
34894-
this->base64_sequence = base64_sequence;
34894+
this->base64_sequence = base64_sequence; this->valid = valid;
3489534895
}
3489634896
~image(){};
3489734897

@@ -35044,7 +35044,7 @@ namespace ollama
3504435044
(*this)["stream"] = stream;
3504535045

3504635046
if (options!=nullptr) (*this)["options"] = options["options"];
35047-
//(*this)["format"] = format; // Commented out as providing the format causes issues with some models.
35047+
(void)format; //(*this)["format"] = format; // Commented out as providing the format causes issues with some models.
3504835048
(*this)["keep_alive"] = keep_alive_duration;
3504935049
type = message_type::chat;
3505035050

@@ -35119,7 +35119,7 @@ namespace ollama
3511935119
return simple_string;
3512035120
}
3512135121

35122-
const bool has_error() const
35122+
bool has_error() const
3512335123
{
3512435124
if ( json_data.contains("error") ) return true;
3512535125
return false;
@@ -35625,7 +35625,6 @@ class Ollama
3562535625
std::string get_version()
3562635626
{
3562735627
std::string version;
35628-
httplib::Client cli("http://localhost:11434");
3562935628

3563035629
auto res = this->cli->Get("/api/version");
3563135630

@@ -35662,12 +35661,13 @@ class Ollama
3566235661

3566335662
private:
3566435663

35664+
/*
3566535665
bool send_request(const ollama::request& request, std::function<void(const ollama::response&)> on_receive_response=nullptr)
3566635666
{
3566735667

3566835668
return true;
3566935669
}
35670-
35670+
*/
3567135671

3567235672
std::string server_url;
3567335673
httplib::Client *cli;
@@ -35830,7 +35830,7 @@ namespace ollama
3583035830
ollama.setWriteTimeout(seconds);
3583135831
}
3583235832

35833-
};
35833+
}
3583435834

3583535835

3583635836
#endif

Diff for: test/test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ TEST_SUITE("Ollama Tests") {
106106
try {
107107
ollama::generate("Non-existent-model", "Requesting this model will throw an error");
108108
}
109-
catch(ollama::exception e) { exception_handled = true; }
109+
catch(ollama::exception& e) { exception_handled = true; }
110110

111111
CHECK( exception_handled );
112112
}

0 commit comments

Comments
 (0)