mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
return style name in prompt handler
This commit is contained in:
1 parent
58c2351c7d
commit
dacef70c32
4 files changed
+31
-6
No files matched your search
@@ -1,3 +1,5 @@
|
||||
use errors::AnyhowResult;
|
||||
|
||||
use crate::payloads::prompt_args::encoded_style_transfer_name::EncodedStyleTransferName;
|
||||
|
||||
// TODO(bt,2024-04-13): Once this gets big enough, design a PromptInnerPayloadBuilder that returns None if no fields were set.
|
||||
@@ -12,3 +14,13 @@ pub struct PromptInnerPayload {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub style_name: Option<EncodedStyleTransferName>,
|
||||
}
|
||||
|
||||
impl PromptInnerPayload{
|
||||
pub fn from_json(json: &str) -> AnyhowResult<Self> {
|
||||
Ok(serde_json::from_str(json)?)
|
||||
}
|
||||
|
||||
pub fn to_json(&self) -> AnyhowResult<String> {
|
||||
Ok(serde_json::to_string(self)?)
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ use errors::AnyhowResult;
|
||||
use tokens::tokens::prompts::PromptToken;
|
||||
use tokens::tokens::users::UserToken;
|
||||
|
||||
use crate::payloads::prompt_args::prompt_inner_payload::PromptInnerPayload;
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct Prompt {
|
||||
pub token: PromptToken,
|
||||
@@ -23,8 +25,7 @@ pub struct Prompt {
|
||||
pub maybe_positive_prompt: Option<String>,
|
||||
pub maybe_negative_prompt: Option<String>,
|
||||
|
||||
// TODO(bt,2024-02-22): Expose this as structured fields.
|
||||
pub maybe_other_args: Option<String>,
|
||||
pub maybe_other_args: Option<PromptInnerPayload>,
|
||||
|
||||
/// For moderators only
|
||||
pub creator_ip_address: Option<String>,
|
||||
@@ -43,7 +44,6 @@ pub struct PromptRaw {
|
||||
pub maybe_positive_prompt: Option<String>,
|
||||
pub maybe_negative_prompt: Option<String>,
|
||||
|
||||
// TODO(bt,2024-02-22): Expose this as structured fields.
|
||||
pub maybe_other_args: Option<String>,
|
||||
|
||||
/// For moderators only
|
||||
@@ -75,7 +75,10 @@ pub async fn get_prompt(
|
||||
maybe_creator_user_token: record.maybe_creator_user_token,
|
||||
maybe_positive_prompt: record.maybe_positive_prompt,
|
||||
maybe_negative_prompt: record.maybe_negative_prompt,
|
||||
maybe_other_args: record.maybe_other_args,
|
||||
maybe_other_args: record.maybe_other_args
|
||||
.as_deref()
|
||||
.map(|args| PromptInnerPayload::from_json(args))
|
||||
.transpose()?,
|
||||
creator_ip_address: record.creator_ip_address,
|
||||
created_at: record.created_at,
|
||||
}))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
use anyhow::anyhow;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use sqlx;
|
||||
use sqlx::{Executor, MySql};
|
||||
|
||||
@@ -8,6 +8,7 @@ use enums::by_table::prompts::prompt_type::PromptType;
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::prompts::PromptToken;
|
||||
use tokens::tokens::users::UserToken;
|
||||
|
||||
use crate::payloads::prompt_args::prompt_inner_payload::PromptInnerPayload;
|
||||
|
||||
pub struct InsertPromptArgs<'e, 'c, E>
|
||||
@@ -47,7 +48,7 @@ pub async fn insert_prompt<'e, 'c : 'e, E>(args: InsertPromptArgs<'e, 'c, E>)
|
||||
let maybe_other_args = match args.maybe_other_args {
|
||||
None => None,
|
||||
Some(inner_payload) => {
|
||||
let encoded = serde_json::ser::to_string(inner_payload)
|
||||
let encoded = inner_payload.to_json()
|
||||
.map_err(|_e| anyhow!("could not encode inner payload"))?;
|
||||
Some(encoded)
|
||||
},
|
||||
|
||||
+9
@@ -130,12 +130,21 @@ pub async fn get_prompt_handler(
|
||||
Ok(Some(result)) => result,
|
||||
};
|
||||
|
||||
let mut maybe_style_name = None;
|
||||
|
||||
if let Some(inner_payload) = &result.maybe_other_args {
|
||||
if let Some(encoded_style_name) = &inner_payload.style_name {
|
||||
maybe_style_name = encoded_style_name.to_style_name();
|
||||
}
|
||||
}
|
||||
|
||||
let response = GetPromptSuccessResponse {
|
||||
success: true,
|
||||
prompt: PromptInfo {
|
||||
token: result.token,
|
||||
maybe_positive_prompt: result.maybe_positive_prompt,
|
||||
maybe_negative_prompt: result.maybe_negative_prompt,
|
||||
maybe_style_name,
|
||||
prompt_type: result.prompt_type,
|
||||
created_at: result.created_at,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user