-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.cpp
More file actions
29 lines (23 loc) · 920 Bytes
/
chat.cpp
File metadata and controls
29 lines (23 loc) · 920 Bytes
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
#include <string>
#include <vector>
#include <iostream>
#include "llama.h"
float * embed(std::string input) {
llama_model_params mparams = llama_model_default_params();
llama_model * model = llama_model_load_from_file("nomic-embed-text-v1.5.Q2_K.gguf", mparams);
llama_context_params cparams = llama_context_default_params();
cparams.embeddings = true;
llama_context * ctx = llama_init_from_model(model, cparams);
std::vector<llama_token> tokens(512);
const llama_vocab* vocab = llama_model_get_vocab(model);
int n = llama_tokenize(vocab, input.c_str(), input.size(), tokens.data(), 512, true, false);
tokens.resize(n);
llama_batch batch = llama_batch_get_one(tokens.data(), tokens.size());
llama_decode(ctx, batch);
return llama_get_embeddings(ctx);
}
int main() {
std::string input;
std::cin >> input;
float * embedded = embed(input);
}