pub struct PromptManager { /* private fields */ }Expand description
Manages prompt fetching, caching, and compilation.
Implementations§
Source§impl PromptManager
impl PromptManager
Sourcepub fn new(config: &LangfuseConfig) -> Self
pub fn new(config: &LangfuseConfig) -> Self
Create a new PromptManager from the given configuration.
Sourcepub async fn get_text_prompt(
&self,
name: &str,
version: Option<i32>,
label: Option<&str>,
) -> Result<TextPromptClient, LangfuseError>
pub async fn get_text_prompt( &self, name: &str, version: Option<i32>, label: Option<&str>, ) -> Result<TextPromptClient, LangfuseError>
Fetch a text prompt from the API (with caching).
- Check the cache.
- On miss,
GET /api/public/v2/prompts/{name}with optionalversion/labelquery params. - Parse the response into a
TextPromptClient. - Store in cache and return.
Sourcepub async fn get_chat_prompt(
&self,
name: &str,
version: Option<i32>,
label: Option<&str>,
) -> Result<ChatPromptClient, LangfuseError>
pub async fn get_chat_prompt( &self, name: &str, version: Option<i32>, label: Option<&str>, ) -> Result<ChatPromptClient, LangfuseError>
Fetch a chat prompt from the API (with caching).
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the prompt cache.
Sourcepub async fn create_text_prompt(
&self,
name: &str,
template: &str,
labels: Option<&[&str]>,
tags: Option<&[&str]>,
config: Option<&Value>,
) -> Result<TextPromptClient, LangfuseError>
pub async fn create_text_prompt( &self, name: &str, template: &str, labels: Option<&[&str]>, tags: Option<&[&str]>, config: Option<&Value>, ) -> Result<TextPromptClient, LangfuseError>
Create a new text prompt via the Langfuse API.
POSTs to /v2/prompts and invalidates any cached entries for this prompt name.
Sourcepub async fn create_chat_prompt(
&self,
name: &str,
messages: &[ChatMessage],
labels: Option<&[&str]>,
tags: Option<&[&str]>,
config: Option<&Value>,
) -> Result<ChatPromptClient, LangfuseError>
pub async fn create_chat_prompt( &self, name: &str, messages: &[ChatMessage], labels: Option<&[&str]>, tags: Option<&[&str]>, config: Option<&Value>, ) -> Result<ChatPromptClient, LangfuseError>
Create a new chat prompt via the Langfuse API.
POSTs to /v2/prompts and invalidates any cached entries for this prompt name.
Sourcepub async fn update_prompt(
&self,
name: &str,
version: i32,
new_labels: &[&str],
) -> Result<(), LangfuseError>
pub async fn update_prompt( &self, name: &str, version: i32, new_labels: &[&str], ) -> Result<(), LangfuseError>
Update a prompt’s labels via the Langfuse API.
PATCHes /v2/prompts/{name} and invalidates cached entries for this prompt name.
Sourcepub async fn get_prompt(
&self,
name: &str,
version: Option<i32>,
label: Option<&str>,
) -> Result<Prompt, LangfuseError>
pub async fn get_prompt( &self, name: &str, version: Option<i32>, label: Option<&str>, ) -> Result<Prompt, LangfuseError>
Fetch a prompt (text or chat) and return it wrapped in the Prompt enum.
Checks the cache first, then fetches from the API. The response type field
determines whether a Prompt::Text or Prompt::Chat is returned.