pub struct Schema { /* private fields */ }Expand description
JSON Schema body for an LLM tool’s parameters
(type / properties / required / …).
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn object() -> Self
pub fn object() -> Self
Object schema ({"type":"object",…}). Default for tool parameters.
Examples found in repository?
examples/full.rs (line 12)
5fn main() -> Result<(), phi::Error> {
6 let mut m = phi::Extension::new("full", "0.1.0");
7
8 m.register_tool(
9 phi::Tool::new(
10 "echo",
11 "Echo the input back",
12 phi::Schema::object()
13 .property("text", phi::Schema::string())
14 .required(["text"]),
15 |args| {
16 let text = String::from_utf8_lossy(args);
17 Ok(phi::ToolResult {
18 content: format!("echo: {text}"),
19 ..Default::default()
20 })
21 },
22 )
23 .detail_from_args(|args| String::from_utf8_lossy(args).into_owned()),
24 );
25
26 m.register_command(
27 "ask",
28 phi::Command::new("Ask a yes/no question", |_args, ctx| {
29 let reply = ctx.confirm("Confirm?", "Proceed with /tmp/x?");
30 if reply.ok {
31 ctx.notify("info", "Confirmed!");
32 } else {
33 ctx.notify("warning", "Declined.");
34 }
35 ctx.submit("follow-up from ask");
36 Ok(())
37 }),
38 );
39
40 m.run()
41}Sourcepub fn string() -> Self
pub fn string() -> Self
Examples found in repository?
examples/full.rs (line 13)
5fn main() -> Result<(), phi::Error> {
6 let mut m = phi::Extension::new("full", "0.1.0");
7
8 m.register_tool(
9 phi::Tool::new(
10 "echo",
11 "Echo the input back",
12 phi::Schema::object()
13 .property("text", phi::Schema::string())
14 .required(["text"]),
15 |args| {
16 let text = String::from_utf8_lossy(args);
17 Ok(phi::ToolResult {
18 content: format!("echo: {text}"),
19 ..Default::default()
20 })
21 },
22 )
23 .detail_from_args(|args| String::from_utf8_lossy(args).into_owned()),
24 );
25
26 m.register_command(
27 "ask",
28 phi::Command::new("Ask a yes/no question", |_args, ctx| {
29 let reply = ctx.confirm("Confirm?", "Proceed with /tmp/x?");
30 if reply.ok {
31 ctx.notify("info", "Confirmed!");
32 } else {
33 ctx.notify("warning", "Declined.");
34 }
35 ctx.submit("follow-up from ask");
36 Ok(())
37 }),
38 );
39
40 m.run()
41}pub fn number() -> Self
pub fn integer() -> Self
pub fn boolean() -> Self
Sourcepub fn array(items: Schema) -> Self
pub fn array(items: Schema) -> Self
Array schema. items must be a builder schema (not Schema::raw).
Sourcepub fn raw(json: impl Into<Vec<u8>>) -> Self
pub fn raw(json: impl Into<Vec<u8>>) -> Self
Opaque JSON Schema bytes (the previous Vec<u8> API).
pub fn description(self, d: impl Into<String>) -> Self
Sourcepub fn property(self, name: impl Into<String>, schema: Schema) -> Self
pub fn property(self, name: impl Into<String>, schema: Schema) -> Self
Add an object property. No-op on non-object / raw schemas.
Examples found in repository?
examples/full.rs (line 13)
5fn main() -> Result<(), phi::Error> {
6 let mut m = phi::Extension::new("full", "0.1.0");
7
8 m.register_tool(
9 phi::Tool::new(
10 "echo",
11 "Echo the input back",
12 phi::Schema::object()
13 .property("text", phi::Schema::string())
14 .required(["text"]),
15 |args| {
16 let text = String::from_utf8_lossy(args);
17 Ok(phi::ToolResult {
18 content: format!("echo: {text}"),
19 ..Default::default()
20 })
21 },
22 )
23 .detail_from_args(|args| String::from_utf8_lossy(args).into_owned()),
24 );
25
26 m.register_command(
27 "ask",
28 phi::Command::new("Ask a yes/no question", |_args, ctx| {
29 let reply = ctx.confirm("Confirm?", "Proceed with /tmp/x?");
30 if reply.ok {
31 ctx.notify("info", "Confirmed!");
32 } else {
33 ctx.notify("warning", "Declined.");
34 }
35 ctx.submit("follow-up from ask");
36 Ok(())
37 }),
38 );
39
40 m.run()
41}Sourcepub fn required<I, S>(self, names: I) -> Self
pub fn required<I, S>(self, names: I) -> Self
Mark object property names as required.
Examples found in repository?
examples/full.rs (line 14)
5fn main() -> Result<(), phi::Error> {
6 let mut m = phi::Extension::new("full", "0.1.0");
7
8 m.register_tool(
9 phi::Tool::new(
10 "echo",
11 "Echo the input back",
12 phi::Schema::object()
13 .property("text", phi::Schema::string())
14 .required(["text"]),
15 |args| {
16 let text = String::from_utf8_lossy(args);
17 Ok(phi::ToolResult {
18 content: format!("echo: {text}"),
19 ..Default::default()
20 })
21 },
22 )
23 .detail_from_args(|args| String::from_utf8_lossy(args).into_owned()),
24 );
25
26 m.register_command(
27 "ask",
28 phi::Command::new("Ask a yes/no question", |_args, ctx| {
29 let reply = ctx.confirm("Confirm?", "Proceed with /tmp/x?");
30 if reply.ok {
31 ctx.notify("info", "Confirmed!");
32 } else {
33 ctx.notify("warning", "Declined.");
34 }
35 ctx.submit("follow-up from ask");
36 Ok(())
37 }),
38 );
39
40 m.run()
41}pub fn additional_properties(self, allow: bool) -> Self
Sourcepub fn enum_values<I, S>(self, values: I) -> Self
pub fn enum_values<I, S>(self, values: I) -> Self
Restrict a string schema to an enum (Codex-style compact enums).
Sourcepub fn to_json_bytes(&self) -> Vec<u8> ⓘ
pub fn to_json_bytes(&self) -> Vec<u8> ⓘ
Serialize to JSON Schema bytes for RegisterTool.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more