2023-06-02 10:47:12 -04:00
|
|
|
#include "llmodel.h"
|
|
|
|
|
2024-05-31 16:34:54 -04:00
|
|
|
#include <algorithm>
|
2023-06-02 10:47:12 -04:00
|
|
|
#include <cassert>
|
2024-05-31 16:34:54 -04:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <functional>
|
2023-06-02 10:47:12 -04:00
|
|
|
#include <iostream>
|
2024-05-31 16:34:54 -04:00
|
|
|
#include <optional>
|
2024-02-21 15:45:32 -05:00
|
|
|
#include <regex>
|
2024-08-01 10:46:36 -04:00
|
|
|
#include <sstream>
|
2024-05-31 16:34:54 -04:00
|
|
|
#include <stdexcept>
|
2024-03-13 18:09:24 -04:00
|
|
|
#include <string>
|
2024-05-31 16:34:54 -04:00
|
|
|
#include <vector>
|
2023-06-02 10:47:12 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
namespace ranges = std::ranges;
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-06-24 18:49:23 -04:00
|
|
|
static bool parsePromptTemplate(const std::string &tmpl, std::vector<std::smatch> &placeholders, std::string &err)
|
|
|
|
{
|
2024-02-21 15:45:32 -05:00
|
|
|
static const std::regex placeholderRegex(R"(%[1-2](?![0-9]))");
|
|
|
|
|
|
|
|
auto it = std::sregex_iterator(tmpl.begin(), tmpl.end(), placeholderRegex);
|
|
|
|
placeholders.clear();
|
|
|
|
placeholders.insert(placeholders.end(), it, std::sregex_iterator());
|
|
|
|
|
|
|
|
if (placeholders.size() > 2) {
|
|
|
|
err = "ERROR: expected at most two placeholders, got " + std::to_string(placeholders.size());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (placeholders.size() >= 1 && placeholders[0].str() != "%1") {
|
|
|
|
err = "ERROR: first placeholder must be %1, got " + placeholders[0].str();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (placeholders.size() >= 2 && placeholders[1].str() != "%2") {
|
|
|
|
err = "ERROR: second placeholder must be %2, got " + placeholders[1].str();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-04 08:59:24 -04:00
|
|
|
void LLModel::prompt(const std::string &prompt,
|
2024-02-21 15:45:32 -05:00
|
|
|
const std::string &promptTemplate,
|
2023-06-04 08:59:24 -04:00
|
|
|
std::function<bool(int32_t)> promptCallback,
|
|
|
|
std::function<bool(int32_t, const std::string&)> responseCallback,
|
2024-08-07 11:25:24 -04:00
|
|
|
bool allowContextShift,
|
2024-02-21 15:45:32 -05:00
|
|
|
PromptContext &promptCtx,
|
|
|
|
bool special,
|
|
|
|
std::string *fakeReply)
|
2023-06-04 08:59:24 -04:00
|
|
|
{
|
|
|
|
if (!isModelLoaded()) {
|
2023-07-08 10:04:38 -04:00
|
|
|
std::cerr << implementation().modelType() << " ERROR: prompt won't work with an unloaded model!\n";
|
2023-06-04 08:59:24 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:32:51 -04:00
|
|
|
if (!supportsCompletion()) {
|
2024-02-21 15:45:32 -05:00
|
|
|
std::string errorMessage = "ERROR: this model does not support text completion or chat!";
|
2023-07-09 11:32:51 -04:00
|
|
|
responseCallback(-1, errorMessage);
|
2024-02-21 15:45:32 -05:00
|
|
|
std::cerr << implementation().modelType() << " " << errorMessage << "\n";
|
2023-07-09 11:32:51 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// sanity checks
|
|
|
|
if (promptCtx.n_past > contextLength()) {
|
2024-08-01 10:46:36 -04:00
|
|
|
std::ostringstream ss;
|
2024-08-07 11:25:24 -04:00
|
|
|
ss << "n_past=" << promptCtx.n_past << " is past end of context length=" << contextLength();
|
2024-08-01 10:46:36 -04:00
|
|
|
throw std::out_of_range(ss.str());
|
|
|
|
}
|
2024-08-07 11:25:24 -04:00
|
|
|
if (promptCtx.n_past > promptCtx.tokens.size()) {
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "n_past=" << promptCtx.n_past << " is past end of token cache length=" << promptCtx.tokens.size();
|
|
|
|
throw std::out_of_range(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
promptCtx.n_ctx = contextLength();
|
|
|
|
promptCtx.n_batch = std::min(promptCtx.n_batch, LLMODEL_MAX_PROMPT_BATCH);
|
|
|
|
|
2024-08-01 10:46:36 -04:00
|
|
|
if (promptCtx.n_past < promptCtx.tokens.size())
|
|
|
|
promptCtx.tokens.resize(promptCtx.n_past);
|
|
|
|
m_tokenize_last_token = promptCtx.tokens.empty() ? -1 : promptCtx.tokens.back(); // not serialized
|
|
|
|
|
2024-02-21 15:45:32 -05:00
|
|
|
// parse the prompt template
|
|
|
|
std::vector<std::smatch> placeholders;
|
|
|
|
{
|
|
|
|
std::string err;
|
|
|
|
if (!parsePromptTemplate(promptTemplate, placeholders, err)) {
|
|
|
|
responseCallback(-1, err);
|
|
|
|
std::cerr << err << "\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto old_n_past = promptCtx.n_past; // prepare to fake n_past for tokenize
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-02-21 15:45:32 -05:00
|
|
|
// tokenize the user prompt
|
|
|
|
std::vector<Token> embd_inp;
|
|
|
|
if (placeholders.empty()) {
|
|
|
|
// this is unusual, but well-defined
|
|
|
|
std::cerr << __func__ << ": prompt template has no placeholder\n";
|
|
|
|
embd_inp = tokenize(promptCtx, promptTemplate, true);
|
|
|
|
} else {
|
|
|
|
// template: beginning of user prompt
|
|
|
|
const auto &phUser = placeholders[0];
|
|
|
|
std::string userPrefix(phUser.prefix());
|
|
|
|
if (!userPrefix.empty()) {
|
|
|
|
embd_inp = tokenize(promptCtx, userPrefix, true);
|
|
|
|
promptCtx.n_past += embd_inp.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// user input (shouldn't have special token processing)
|
|
|
|
auto tokens = tokenize(promptCtx, prompt, special);
|
|
|
|
embd_inp.insert(embd_inp.end(), tokens.begin(), tokens.end());
|
|
|
|
promptCtx.n_past += tokens.size();
|
|
|
|
|
|
|
|
// template: end of user prompt + start of assistant prompt
|
|
|
|
size_t start = phUser.position() + phUser.length();
|
|
|
|
size_t end = placeholders.size() >= 2 ? placeholders[1].position() : promptTemplate.length();
|
|
|
|
auto userToAsst = promptTemplate.substr(start, end - start);
|
|
|
|
if (!userToAsst.empty()) {
|
|
|
|
tokens = tokenize(promptCtx, userToAsst, true);
|
|
|
|
embd_inp.insert(embd_inp.end(), tokens.begin(), tokens.end());
|
|
|
|
promptCtx.n_past += tokens.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
promptCtx.n_past = old_n_past; // restore n_past so decodePrompt can increment it
|
|
|
|
|
|
|
|
// decode the user prompt
|
2024-08-07 11:25:24 -04:00
|
|
|
if (!decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp))
|
2024-07-01 11:33:46 -04:00
|
|
|
return; // error
|
2024-02-21 15:45:32 -05:00
|
|
|
|
|
|
|
// decode the assistant's reply, either generated or spoofed
|
|
|
|
if (fakeReply == nullptr) {
|
2024-08-07 11:25:24 -04:00
|
|
|
generateResponse(responseCallback, allowContextShift, promptCtx);
|
2024-02-21 15:45:32 -05:00
|
|
|
} else {
|
|
|
|
embd_inp = tokenize(promptCtx, *fakeReply, false);
|
2024-08-07 11:25:24 -04:00
|
|
|
if (!decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp))
|
2024-07-01 11:33:46 -04:00
|
|
|
return; // error
|
2024-02-21 15:45:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// decode the rest of the prompt template
|
2024-02-26 13:11:15 -05:00
|
|
|
// template: end of assistant prompt
|
|
|
|
std::string asstSuffix;
|
2024-02-21 15:45:32 -05:00
|
|
|
if (placeholders.size() >= 2) {
|
|
|
|
size_t start = placeholders[1].position() + placeholders[1].length();
|
2024-02-26 13:11:15 -05:00
|
|
|
asstSuffix = promptTemplate.substr(start);
|
|
|
|
} else {
|
|
|
|
asstSuffix = "\n\n"; // default to a blank link, good for e.g. Alpaca
|
|
|
|
}
|
|
|
|
if (!asstSuffix.empty()) {
|
|
|
|
embd_inp = tokenize(promptCtx, asstSuffix, true);
|
2024-08-07 11:25:24 -04:00
|
|
|
decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp);
|
2024-02-21 15:45:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-01 11:33:46 -04:00
|
|
|
// returns false on error
|
|
|
|
bool LLModel::decodePrompt(std::function<bool(int32_t)> promptCallback,
|
2024-02-21 15:45:32 -05:00
|
|
|
std::function<bool(int32_t, const std::string&)> responseCallback,
|
2024-08-07 11:25:24 -04:00
|
|
|
bool allowContextShift,
|
2024-02-21 15:45:32 -05:00
|
|
|
PromptContext &promptCtx,
|
|
|
|
std::vector<Token> embd_inp) {
|
2023-06-04 08:59:24 -04:00
|
|
|
if ((int) embd_inp.size() > promptCtx.n_ctx - 4) {
|
|
|
|
responseCallback(-1, "ERROR: The prompt size exceeds the context window size and cannot be processed.");
|
2023-07-09 11:00:20 -04:00
|
|
|
std::cerr << implementation().modelType() << " ERROR: The prompt is " << embd_inp.size() <<
|
|
|
|
" tokens and the context window is " << promptCtx.n_ctx << "!\n";
|
2024-07-01 11:33:46 -04:00
|
|
|
return false;
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// FIXME(jared): There are mitigations for this situation, such as making room before
|
|
|
|
// copying the prompt context, or restoring the KV cache when we restore the prompt
|
|
|
|
// context.
|
|
|
|
if (!allowContextShift && promptCtx.n_past + embd_inp.size() > promptCtx.n_ctx) {
|
|
|
|
std::cerr << "LLModel Warning: Not enough space, n_past=" << promptCtx.n_past << ", n_eval=" << embd_inp.size()
|
|
|
|
<< ", n_ctx=" << promptCtx.n_ctx << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
|
|
|
|
// process the prompt in batches
|
|
|
|
size_t i = 0;
|
|
|
|
while (i < embd_inp.size()) {
|
|
|
|
size_t batch_end = std::min(i + promptCtx.n_batch, embd_inp.size());
|
|
|
|
std::vector<Token> batch(embd_inp.begin() + i, embd_inp.begin() + batch_end);
|
|
|
|
|
|
|
|
// Check if the context has run out...
|
|
|
|
if (promptCtx.n_past + int32_t(batch.size()) > promptCtx.n_ctx) {
|
2024-08-07 11:25:24 -04:00
|
|
|
assert(allowContextShift);
|
|
|
|
shiftContext(promptCtx);
|
2023-06-04 08:59:24 -04:00
|
|
|
assert(promptCtx.n_past + int32_t(batch.size()) <= promptCtx.n_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!evalTokens(promptCtx, batch)) {
|
2023-07-08 10:04:38 -04:00
|
|
|
std::cerr << implementation().modelType() << " ERROR: Failed to process prompt\n";
|
2024-07-01 11:33:46 -04:00
|
|
|
return false;
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t tokens = batch_end - i;
|
|
|
|
for (size_t t = 0; t < tokens; ++t) {
|
|
|
|
promptCtx.tokens.push_back(batch.at(t));
|
2023-10-03 12:42:31 -04:00
|
|
|
promptCtx.n_past += 1;
|
2023-06-04 08:59:24 -04:00
|
|
|
if (!promptCallback(batch.at(t)))
|
2024-07-01 11:33:46 -04:00
|
|
|
return false;
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
|
|
|
i = batch_end;
|
|
|
|
}
|
2024-07-01 11:33:46 -04:00
|
|
|
|
|
|
|
return true;
|
2024-02-21 15:45:32 -05:00
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
/*
|
|
|
|
* If string s overlaps with the string key such that some prefix of the key is at the end
|
|
|
|
* of the string, return the position in s where the first match starts. Otherwise, return
|
|
|
|
* std::string::npos. Examples:
|
|
|
|
* s = "bfo", key = "foo" -> 1
|
|
|
|
* s = "fooa", key = "foo" -> npos
|
|
|
|
*/
|
|
|
|
static std::string::size_type stringsOverlap(const std::string &s, const std::string &key)
|
|
|
|
{
|
|
|
|
if (s.empty() || key.empty())
|
|
|
|
throw std::invalid_argument("arguments to stringsOverlap must not be empty");
|
|
|
|
|
|
|
|
for (int start = std::max(0, int(s.size()) - int(key.size())); start < s.size(); start++) {
|
|
|
|
if (s.compare(start, s.size(), key, 0, s.size() - start) == 0)
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
return std::string::npos;
|
|
|
|
}
|
|
|
|
|
2024-02-21 15:45:32 -05:00
|
|
|
void LLModel::generateResponse(std::function<bool(int32_t, const std::string&)> responseCallback,
|
2024-08-07 11:25:24 -04:00
|
|
|
bool allowContextShift,
|
2024-02-21 15:45:32 -05:00
|
|
|
PromptContext &promptCtx) {
|
2024-08-07 11:25:24 -04:00
|
|
|
static const char *stopSequences[] {
|
|
|
|
"### Instruction", "### Prompt", "### Response", "### Human", "### Assistant", "### Context",
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't even start if there is no room
|
|
|
|
if (!promptCtx.n_predict)
|
|
|
|
return;
|
|
|
|
if (!allowContextShift && promptCtx.n_past >= promptCtx.n_ctx) {
|
|
|
|
std::cerr << "LLModel Warning: Not enough space, n_past=" << promptCtx.n_past << ", n_ctx=" << promptCtx.n_ctx
|
|
|
|
<< "\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-04 08:59:24 -04:00
|
|
|
std::string cachedResponse;
|
|
|
|
std::vector<Token> cachedTokens;
|
2024-08-07 11:25:24 -04:00
|
|
|
int n_predicted = 0;
|
|
|
|
|
|
|
|
// Predict next tokens
|
|
|
|
for (bool stop = false; !stop;) {
|
|
|
|
// Sample next token
|
|
|
|
std::optional<Token> new_tok = sampleToken(promptCtx);
|
|
|
|
std::string new_piece = tokenToString(new_tok.value());
|
|
|
|
cachedTokens.push_back(new_tok.value());
|
|
|
|
cachedResponse += new_piece;
|
|
|
|
|
|
|
|
auto accept = [this, &promptCtx, &cachedTokens, &new_tok, allowContextShift]() -> bool {
|
|
|
|
// Shift context if out of space
|
|
|
|
if (promptCtx.n_past >= promptCtx.n_ctx) {
|
|
|
|
(void)allowContextShift;
|
|
|
|
assert(allowContextShift);
|
|
|
|
shiftContext(promptCtx);
|
|
|
|
assert(promptCtx.n_past < promptCtx.n_ctx);
|
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Accept the token
|
|
|
|
Token tok = std::exchange(new_tok, std::nullopt).value();
|
|
|
|
if (!evalTokens(promptCtx, { tok })) {
|
|
|
|
// TODO(jared): raise an exception
|
|
|
|
std::cerr << implementation().modelType() << " ERROR: Failed to predict next token\n";
|
|
|
|
return false;
|
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
promptCtx.tokens.push_back(tok);
|
|
|
|
promptCtx.n_past += 1;
|
|
|
|
return true;
|
|
|
|
};
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Check for EOS
|
|
|
|
auto lengthLimit = std::string::npos;
|
|
|
|
for (const auto token : endTokens()) {
|
|
|
|
if (new_tok == token) {
|
|
|
|
stop = true;
|
|
|
|
lengthLimit = cachedResponse.size() - new_piece.size();
|
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
if (lengthLimit != std::string::npos) {
|
|
|
|
// EOS matched
|
|
|
|
} else if (!isSpecialToken(new_tok.value())) {
|
|
|
|
// Check if the response contains a stop sequence
|
|
|
|
for (const auto &p : stopSequences) {
|
|
|
|
auto match = cachedResponse.find(p);
|
|
|
|
if (match != std::string::npos) stop = true;
|
|
|
|
lengthLimit = std::min(lengthLimit, match);
|
|
|
|
if (match == 0) break;
|
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Check if the response matches the start of a stop sequence
|
|
|
|
if (lengthLimit == std::string::npos) {
|
|
|
|
for (const auto &p : stopSequences) {
|
|
|
|
auto match = stringsOverlap(cachedResponse, p);
|
|
|
|
lengthLimit = std::min(lengthLimit, match);
|
|
|
|
if (match == 0) break;
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 11:49:01 -04:00
|
|
|
} else if (ranges::find(stopSequences, new_piece) < std::end(stopSequences)) {
|
2024-08-07 11:25:24 -04:00
|
|
|
// Special tokens must exactly match a stop sequence
|
|
|
|
stop = true;
|
|
|
|
lengthLimit = cachedResponse.size() - new_piece.size();
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Optionally stop if the context will run out
|
|
|
|
if (!allowContextShift && promptCtx.n_past + cachedTokens.size() >= promptCtx.n_ctx) {
|
|
|
|
std::cerr << "LLModel Warning: Not enough space, n_past=" << promptCtx.n_past << ", n_ctx="
|
|
|
|
<< promptCtx.n_ctx << "\n";
|
|
|
|
stop = true;
|
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Empty the cache, up to the length limit
|
|
|
|
std::string::size_type responseLength = 0;
|
|
|
|
while (!cachedTokens.empty()) {
|
|
|
|
Token tok = cachedTokens.front();
|
|
|
|
std::string piece = tokenToString(tok);
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Stop if the piece (or part of it) does not fit within the length limit
|
|
|
|
if (responseLength + (stop ? 1 : piece.size()) > lengthLimit)
|
2023-06-04 08:59:24 -04:00
|
|
|
break;
|
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Remove token from cache
|
|
|
|
assert(cachedResponse.starts_with(piece));
|
|
|
|
cachedTokens.erase(cachedTokens.begin(), cachedTokens.begin() + 1);
|
|
|
|
cachedResponse.erase(cachedResponse.begin(), cachedResponse.begin() + piece.size());
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Accept the token, if needed (not cached)
|
|
|
|
if (cachedTokens.empty() && new_tok && !accept())
|
|
|
|
return;
|
2023-06-04 08:59:24 -04:00
|
|
|
|
2024-08-07 11:25:24 -04:00
|
|
|
// Send the token
|
|
|
|
if (!responseCallback(tok, piece) || ++n_predicted >= promptCtx.n_predict) {
|
|
|
|
stop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(jared): we could avoid printing partial stop sequences if we didn't have to
|
|
|
|
// output token IDs and could cache a partial token for the next prompt call
|
|
|
|
responseLength += piece.size();
|
|
|
|
}
|
|
|
|
assert(cachedTokens.empty() == cachedResponse.empty());
|
|
|
|
|
|
|
|
// Accept the token, if needed (in cache)
|
|
|
|
if (new_tok) {
|
|
|
|
assert(!cachedTokens.empty() && cachedTokens.back() == new_tok);
|
|
|
|
if (stop) {
|
|
|
|
cachedTokens.pop_back();
|
|
|
|
} else if (!accept()) {
|
2023-06-04 08:59:24 -04:00
|
|
|
return;
|
2024-08-07 11:25:24 -04:00
|
|
|
}
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
|
|
|
}
|
2024-08-07 11:25:24 -04:00
|
|
|
|
|
|
|
auto &tokens = promptCtx.tokens;
|
|
|
|
if (tokens.size() < cachedTokens.size()) {
|
|
|
|
/* This is theoretically possible if the longest stop sequence is greater than
|
|
|
|
* n_ctx * contextErase tokens. */
|
|
|
|
throw std::runtime_error("shifted too much context, can't go back");
|
|
|
|
}
|
|
|
|
|
|
|
|
auto discard_start = tokens.end() - cachedTokens.size();
|
|
|
|
assert(std::equal(discard_start, tokens.end(), cachedTokens.begin()));
|
|
|
|
tokens.erase(discard_start, tokens.end());
|
|
|
|
|
|
|
|
promptCtx.n_past -= cachedTokens.size();
|
2023-06-04 08:59:24 -04:00
|
|
|
}
|
2023-07-09 11:32:51 -04:00
|
|
|
|
2024-03-13 18:09:24 -04:00
|
|
|
void LLModel::embed(
|
|
|
|
const std::vector<std::string> &texts, float *embeddings, std::optional<std::string> prefix, int dimensionality,
|
2024-04-12 16:00:39 -04:00
|
|
|
size_t *tokenCount, bool doMean, bool atlas, EmbedCancelCallback *cancelCb
|
2024-03-13 18:09:24 -04:00
|
|
|
) {
|
|
|
|
(void)texts;
|
|
|
|
(void)embeddings;
|
|
|
|
(void)prefix;
|
|
|
|
(void)dimensionality;
|
2024-03-20 11:24:02 -04:00
|
|
|
(void)tokenCount;
|
2024-03-13 18:09:24 -04:00
|
|
|
(void)doMean;
|
|
|
|
(void)atlas;
|
2024-04-12 16:00:39 -04:00
|
|
|
(void)cancelCb;
|
2024-03-13 18:09:24 -04:00
|
|
|
throw std::logic_error(std::string(implementation().modelType()) + " does not support embeddings");
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLModel::embed(
|
2024-03-20 11:24:02 -04:00
|
|
|
const std::vector<std::string> &texts, float *embeddings, bool isRetrieval, int dimensionality, size_t *tokenCount,
|
|
|
|
bool doMean, bool atlas
|
2024-03-13 18:09:24 -04:00
|
|
|
) {
|
|
|
|
(void)texts;
|
|
|
|
(void)embeddings;
|
|
|
|
(void)isRetrieval;
|
|
|
|
(void)dimensionality;
|
2024-03-20 11:24:02 -04:00
|
|
|
(void)tokenCount;
|
2024-03-13 18:09:24 -04:00
|
|
|
(void)doMean;
|
|
|
|
(void)atlas;
|
|
|
|
throw std::logic_error(std::string(implementation().modelType()) + " does not support embeddings");
|
2023-07-09 11:32:51 -04:00
|
|
|
}
|