prompty icon indicating copy to clipboard operation
prompty copied to clipboard

.NET prompty attribute

Open rysweet opened this issue 9 months ago • 3 comments

adds a [Prompty(File=...)] attribute enabling specifying the prompts file on a class or method

see #205

/// <summary>
/// Prompty Attribute - used to load a prompty file or resource from an attribute
/// </summary>
/// <usage>
/// [Prompty("prompty/basic.prompty"]
/// [Prompty("prompty/embedded-resource-path.prompty", IsResource = true, Configuration = "default", Params = new string[] { "question", "answer" })]
/// public class MyClass
/// {...} 
/// in a class or method then use the attribute to load the prompty
/// ...
/// var prompty = (PromptyAttribute)Attribute.GetCustomAttribute(typeof(MyClass), typeof(PromptyAttribute));
/// var messages = prompty.Messages;
/// ...
/// </usage>

Note: you can only specify params that are strings. that is a limitation of attribs. you can still Prepare(new Dictionary<string, object) manually.

rysweet avatar Mar 13 '25 16:03 rysweet

please note: Co-Autohored by: @IntrepidIcarus (Dustin Duran)

rysweet avatar Mar 14 '25 19:03 rysweet

Are there any issues with file normalization when using a stream? In the python version you can explode out a section of the frontmatter by adding a ${file:my_props.json} to any part of the tree and it will load my_props.json based upon the relative path to the parent prompty file. Does this work the same way?

sethjuarez avatar Mar 23 '25 07:03 sethjuarez

Are there any issues with file normalization when using a stream? In the python version you can explode out a section of the frontmatter by adding a ${file:my_props.json} to any part of the tree and it will load my_props.json based upon the relative path to the parent prompty file. Does this work the same way?

no idea - my assumption is that this would be down to the Json serializer rather than the file IO.

rysweet avatar Apr 11 '25 16:04 rysweet