Skip to content

Commit a26d552

Browse files
committed
Update project configuration and add LlamaContext and LlamaModel classes
1 parent 3514422 commit a26d552

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

demo/project.godot

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ config_version=5
1111
[application]
1212

1313
config/name="godot cpp template"
14-
config/features=PackedStringArray("4.1", "Forward Plus")
14+
config/features=PackedStringArray("4.2", "Forward Plus")
1515
config/icon="res://icon.svg"

src/llama_context.cpp

Whitespace-only changes.

src/llama_context.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef LLAMA_CONTEXT_H
2+
#define LLAMA_CONTEXT_H
3+
4+
#include <godot_cpp/classes/node.hpp>
5+
#include "llama_model.h"
6+
7+
namespace godot {
8+
class LlamaContext : public Node {
9+
GDCLASS(LlamaContext, Node)
10+
11+
private:
12+
LlamaModel model;
13+
14+
protected:
15+
static void _bind_methods();
16+
17+
public:
18+
LlamaContext();
19+
~LlamaContext();
20+
};
21+
}
22+
23+
#endif

src/llama_model.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "llama.h"
2+
#include "common.h"
3+
#include "llama_model.h"
4+
#include <godot_cpp/core/class_db.hpp>
5+
6+
using namespace godot;
7+
8+
void LlamaModel::_bind_methods() {
9+
}
10+
11+
LlamaModel::LlamaModel() {
12+
llama_model_params model_params = llama_model_default_params();
13+
model = llama_load_model_from_file(resource_path, model_params);
14+
15+
if (model == NULL) {
16+
ERR_FAIL_NULL_MSG(model, "Unable to load model");
17+
}
18+
}
19+
20+
LlamaModel::~LlamaModel() {
21+
llama_free_model(model);
22+
}

src/llama_model.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef LLAMA_MODEL_H
2+
#define LLAMA_MODEL_H
3+
4+
#include "llama.h"
5+
#include <godot_cpp/classes/resource.hpp>
6+
7+
namespace godot {
8+
9+
class LlamaModel : public Resource {
10+
GDCLASS(LlamaModel, Resource)
11+
12+
private:
13+
const char* resource_path;
14+
llama_model* model;
15+
16+
protected:
17+
static void _bind_methods();
18+
19+
public:
20+
LlamaModel();
21+
~LlamaModel();
22+
};
23+
24+
} //namespace godot
25+
26+
#endif

0 commit comments

Comments
 (0)