Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToSchema doesn't work on one particular #[serde(flatten)] #1076

Open
cryscan opened this issue Mar 6, 2025 · 0 comments
Open

ToSchema doesn't work on one particular #[serde(flatten)] #1076

cryscan opened this issue Mar 6, 2025 · 0 comments

Comments

@cryscan
Copy link

cryscan commented Mar 6, 2025

Here is the definition of types:

#[derive(Debug, Clone, Derivative, Serialize, Deserialize, ToSchema)]
#[derivative(Default)]
#[serde(default)]
pub struct NucleusParams {
    #[derivative(Default(value = "0.5"))]
    pub top_p: f32,
    #[derivative(Default(value = "128"))]
    pub top_k: usize,
    #[derivative(Default(value = "1.0"))]
    pub temperature: f32,
    #[derivative(Default(value = "0.3"))]
    pub presence_penalty: f32,
    #[derivative(Default(value = "0.3"))]
    pub frequency_penalty: f32,
    #[derivative(Default(value = "0.99654026"))]
    pub penalty_decay: f32,
}



#[derive(Debug, Derivative, Deserialize, ToSchema)]
#[derivative(Default)]
#[serde(default)]
#[salvo(schema(
    example = json!({
        "messages": [
            {
                "role": "user",
                "content": "Hi!"
            },
            {
                "role": "assistant",
                "content": "Hello, I am your AI assistant. If you have any questions or instructions, please let me know!"
            },
            {
                "role": "user",
                "content": "Tell me about water."
            }
        ],
        "names": {
            "user": "User",
            "assistant": "Assistant"
        },
        "template": {
            "record": "{role}: {content}",
            "prefix": "{assistant}:",
            "sep": "\n\n"
        },
        "stop": [
            "\n\nUser:"
        ],
        "stream": false,
        "max_tokens": 1000,
        "sampler_override": {
            "type": "Nucleus",
            "top_p": 0.5,
            "top_k": 128,
            "temperature": 1,
            "presence_penalty": 0.3,
            "frequency_penalty": 0.3,
            "penalty_decay": 0.99654026
        },
        "state": "00000000-0000-0000-0000-000000000000"
    })
))]
struct ChatRequest {
    messages: Array<ChatRecord>,
    names: HashMap<Role, String>,
    template: ChatTemplate,
    state: InputState,
    #[derivative(Default(value = "256"))]
    max_tokens: usize,
    #[derivative(Default(value = "Array::Item(\"\\n\\n\".into())"))]
    stop: Array<String>,
    stream: bool,
    #[serde(alias = "logit_bias")]
    bias: HashMap<u16, f32>,
    bnf_schema: Option<String>,
    #[serde(flatten)]
    sampler: NucleusParams,
    sampler_override: Option<SamplerParams>,
}

With #[serde(flatten)], there is an error on ToSchema:

error[E0599]: no method named `example` found for struct `salvo::salvo_oapi::schema::AllOf` in the current scope
  --> crates\ai00-server\src\api\oai\chat.rs:67:42
   |
67 | #[derive(Debug, Derivative, Deserialize, ToSchema)]
   |                                          ^^^^^^^^
   |
   = note: this error originates in the derive macro `ToSchema` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `example` found for struct `salvo::salvo_oapi::schema::AllOf` in the current scope
  --> crates\ai00-server\src\api\oai\completion.rs:23:42
   |
23 | #[derive(Debug, Derivative, Deserialize, ToSchema)]
   |                                          ^^^^^^^^
   |
   = note: this error originates in the derive macro `ToSchema` (in Nightly builds, run with -Z macro-backtrace for more info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant