Archived
core: a speech model without instructions, and a refusal's reason from its text_prepare -- an audio generator may declare tmpl_plain alone (a request's instructions refused by name), and the reason a plugin leaves in the output buffer reaches the caller
This commit is contained in:
1 parent
61abb990ab
commit
832a88faac
7 files changed
+30
-9
No files matched your search
@@ -1361,7 +1361,12 @@ int Builder::declare_audio_generator(const RadAudioGenDecl* d) {
|
||||
: prog_.generator.layout != 0 ? "an image generator" : "a video generator");
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
if (!d->tmpl || !std::strstr(d->tmpl, "{input}") || !std::strstr(d->tmpl, "{instructions}")) {
|
||||
if (!d->tmpl && !d->tmpl_plain) {
|
||||
err(RAD_E_INVAL, "declare_audio_generator '%s': no prompt template (tmpl or tmpl_plain)",
|
||||
nm);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
if (d->tmpl && (!std::strstr(d->tmpl, "{input}") || !std::strstr(d->tmpl, "{instructions}"))) {
|
||||
err(RAD_E_INVAL, "declare_audio_generator '%s': tmpl needs {instructions} and {input}", nm);
|
||||
return RAD_E_INVAL;
|
||||
}
|
||||
@@ -1460,7 +1465,7 @@ int Builder::declare_audio_generator(const RadAudioGenDecl* d) {
|
||||
!buf_ok(d->audio_out, RAD_F32, win_samples * d->channels, "audio_out"))
|
||||
return RAD_E_INVAL;
|
||||
prog_.agen_str.name = nm;
|
||||
prog_.agen_str.tmpl = d->tmpl;
|
||||
prog_.agen_str.tmpl = d->tmpl ? d->tmpl : "";
|
||||
prog_.agen_str.tmpl_plain = d->tmpl_plain ? d->tmpl_plain : "";
|
||||
prog_.agen_str.neg_tmpl = d->neg_tmpl ? d->neg_tmpl : "";
|
||||
prog_.audio_gen = *d;
|
||||
|
||||
@@ -270,7 +270,12 @@ int rad_tools_text_prepare(const LoadedPlugins& lp, int field, const std::string
|
||||
std::string buf(in.size() * 2 + 64, '\0');
|
||||
for (int tries = 0; tries < 2; ++tries) {
|
||||
const int64_t n = ap->arch_text_prepare(field, in.c_str(), &buf[0], (int64_t)buf.size());
|
||||
if (n < 0) return (int)n;
|
||||
if (n < 0) {
|
||||
/* The plugin's reason, when it left one in the (zeroed) buffer. */
|
||||
buf.resize(std::strlen(buf.c_str()));
|
||||
*out = std::move(buf);
|
||||
return (int)n;
|
||||
}
|
||||
if (n < (int64_t)buf.size()) {
|
||||
buf.resize((size_t)n);
|
||||
*out = std::move(buf);
|
||||
|
||||
@@ -93,7 +93,7 @@ const RadAudioFormat* rad_tools_audio_format(const LoadedPlugins& plugins, const
|
||||
* (rad_arch_text_prepare): RAD_OK with the result in `*out` (the text unchanged when the plugin
|
||||
* states no rewrite), or the plugin's negative status. */
|
||||
int rad_tools_text_prepare(const LoadedPlugins& plugins, int field, const std::string& in,
|
||||
std::string* out);
|
||||
std::string* out); /* on a refusal, `out` is its reason or "" */
|
||||
|
||||
/* The architecture plugin's video positions (rad_arch_video_positions), or null when it exports
|
||||
* none. */
|
||||
|
||||
+3
-2
@@ -2471,8 +2471,9 @@ int Engine::run_server() {
|
||||
std::string* why) const override {
|
||||
const int s = rad_tools_text_prepare(*plugins, field, in, out);
|
||||
if (s < 0 && why)
|
||||
*why = s == RAD_E_INVAL ? "the model cannot take this text"
|
||||
: std::string(rad_strerror(s));
|
||||
*why = !out->empty() ? *out
|
||||
: s == RAD_E_INVAL ? "the model cannot take this text"
|
||||
: std::string(rad_strerror(s));
|
||||
return s;
|
||||
}
|
||||
int submit(std::unique_ptr<gen::AudioRequest> r, std::string* why) override {
|
||||
|
||||
@@ -110,6 +110,9 @@ int Server::speech_request(const json& body, const std::string& text,
|
||||
return fail(err_bad("instructions", "this model needs instructions, as a non-empty "
|
||||
"string: for a song its genre, mood, vocals and "
|
||||
"instruments"));
|
||||
if (!inst.empty() && info.tmpl.empty())
|
||||
return fail(err_unsupported("instructions", "this model takes no instructions; its "
|
||||
"direction is written in the input"));
|
||||
if (body.contains("speed") && !body["speed"].is_null() &&
|
||||
!(body["speed"].is_number() && body["speed"].get<double>() == 1.0))
|
||||
return fail(err_unsupported("speed", "this model keeps its own tempo; the instructions "
|
||||
|
||||
Reference in new issue
Block a user