Skip to content

Commit c80cd33

Browse files
authored
Merge pull request #5 from otapiero/ouriel/add-chat-promps
Add first-class support for chat prompts and Langfuse API
2 parents 73ad21a + e4edb73 commit c80cd33

14 files changed

+495
-44
lines changed

Interfaces/IDefaultPromptsProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ public interface IDefaultPromptsProvider
77
{
88
IReadOnlyDictionary<string, string> GetDefaults();
99

10+
IReadOnlyDictionary<string, ChatMessage[]> GetChatDefaults();
11+
1012
IReadOnlyDictionary<string, PromptConfiguration> GetPromptKeys();
1113
}

Interfaces/ILangfuseService.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ public interface ILangfuseService
1818
string? label = null,
1919
CancellationToken cancellationToken = default);
2020

21+
/// <summary>
22+
/// Get a chat prompt by name from Langfuse API.
23+
/// </summary>
24+
/// <param name="promptName">The name of the chat prompt</param>
25+
/// <param name="version">Optional version of the prompt to retrieve</param>
26+
/// <param name="label">Optional label of the prompt (defaults to "production" if no label or version is set)</param>
27+
/// <param name="cancellationToken">Cancellation token</param>
28+
/// <returns>The Langfuse chat prompt model</returns>
29+
Task<LangfuseChatPromptModel?> GetChatPromptAsync(
30+
string promptName,
31+
int? version = null,
32+
string? label = null,
33+
CancellationToken cancellationToken = default);
34+
2135
/// <summary>
2236
/// Get all prompts from Langfuse API.
2337
/// </summary>
@@ -35,6 +49,16 @@ Task<CreateLangfusePromptResponse> CreatePromptAsync(
3549
CreateLangfusePromptRequest request,
3650
CancellationToken cancellationToken = default);
3751

52+
/// <summary>
53+
/// Create a new version for the chat prompt with the given name in Langfuse API.
54+
/// </summary>
55+
/// <param name="request">The chat prompt creation request</param>
56+
/// <param name="cancellationToken">Cancellation token</param>
57+
/// <returns>The created chat prompt response</returns>
58+
Task<CreateLangfuseChatPromptResponse> CreateChatPromptAsync(
59+
CreateLangfuseChatPromptRequest request,
60+
CancellationToken cancellationToken = default);
61+
3862
/// <summary>
3963
/// Update labels for a specific prompt version in Langfuse API.
4064
/// </summary>

Interfaces/IPromptService.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public interface IPromptService
99
/// </summary>
1010
Task<PromptResponse> CreatePromptAsync(CreatePromptRequest request, CancellationToken cancellationToken = default);
1111

12+
/// <summary>
13+
/// Create a new chat prompt version in Langfuse
14+
/// </summary>
15+
Task<ChatPromptResponse> CreateChatPromptAsync(CreateChatPromptRequest request, CancellationToken cancellationToken = default);
16+
1217
/// <summary>
1318
/// Get a prompt by key with optional version or label. Falls back to local defaults if Langfuse is unavailable.
1419
/// </summary>
@@ -18,6 +23,15 @@ public interface IPromptService
1823
/// <param name="cancellationToken">Cancellation token</param>
1924
Task<PromptResponse?> GetPromptAsync(string promptKey, int? version = null, string? label = null, CancellationToken cancellationToken = default);
2025

26+
/// <summary>
27+
/// Get a chat prompt by key with optional version or label. Falls back to local defaults if Langfuse is unavailable.
28+
/// </summary>
29+
/// <param name="promptKey">The prompt key/name</param>
30+
/// <param name="version">Optional specific version number</param>
31+
/// <param name="label">Optional label (e.g., "production", "latest")</param>
32+
/// <param name="cancellationToken">Cancellation token</param>
33+
Task<ChatPromptResponse?> GetChatPromptAsync(string promptKey, int? version = null, string? label = null, CancellationToken cancellationToken = default);
34+
2135
/// <summary>
2236
/// Get all prompts from Langfuse
2337
/// </summary>

Models/ChatMessage.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace PromptProvider.Models;
4+
5+
public record ChatMessage
6+
{
7+
[JsonPropertyName("role")]
8+
public required string Role { get; set; }
9+
10+
[JsonPropertyName("content")]
11+
public required string Content { get; set; }
12+
}

Models/ChatPromptResponse.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace PromptProvider.Models;
2+
3+
public record ChatPromptResponse
4+
{
5+
public required string PromptKey { get; set; }
6+
public required ChatMessage[] ChatMessages { get; set; }
7+
public int? Version { get; set; }
8+
public string[]? Labels { get; set; }
9+
public string[]? Tags { get; set; }
10+
public string? Type { get; set; }
11+
public LangfusePromptConfiguration? Config { get; set; }
12+
public string? Source { get; set; } // "Langfuse" or "Local"
13+
}

Models/CreateChatPromptRequest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PromptProvider.Models;
2+
3+
public record CreateChatPromptRequest
4+
{
5+
public required string PromptKey { get; set; }
6+
public required ChatMessage[] ChatMessages { get; set; }
7+
public string? CommitMessage { get; set; }
8+
public string[]? Labels { get; set; }
9+
public string[]? Tags { get; set; }
10+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace PromptProvider.Models;
4+
5+
public record CreateLangfuseChatPromptRequest
6+
{
7+
[JsonPropertyName("name")]
8+
public required string Name { get; set; }
9+
10+
[JsonPropertyName("prompt")]
11+
public required ChatMessage[] Prompt { get; set; }
12+
13+
[JsonPropertyName("type")]
14+
public required string Type { get; set; }
15+
16+
[JsonPropertyName("commitMessage")]
17+
public string? CommitMessage { get; set; }
18+
19+
[JsonPropertyName("config")]
20+
public object? Config { get; set; }
21+
22+
[JsonPropertyName("labels")]
23+
public string[]? Labels { get; set; }
24+
25+
[JsonPropertyName("tags")]
26+
public string[]? Tags { get; set; }
27+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace PromptProvider.Models;
4+
5+
public record CreateLangfuseChatPromptResponse
6+
{
7+
[JsonPropertyName("name")]
8+
public required string Name { get; set; }
9+
10+
[JsonPropertyName("prompt")]
11+
public required ChatMessage[] Prompt { get; set; }
12+
13+
[JsonPropertyName("type")]
14+
public required string Type { get; set; }
15+
16+
[JsonPropertyName("version")]
17+
public int Version { get; set; }
18+
19+
[JsonPropertyName("config")]
20+
public object? Config { get; set; }
21+
22+
[JsonPropertyName("labels")]
23+
public required string[] Labels { get; set; }
24+
25+
[JsonPropertyName("tags")]
26+
public required string[] Tags { get; set; }
27+
28+
[JsonPropertyName("commitMessage")]
29+
public string? CommitMessage { get; set; }
30+
31+
[JsonPropertyName("resolutionGraph")]
32+
public object? ResolutionGraph { get; set; }
33+
}

Models/LangfuseChatPromptModel.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace PromptProvider.Models;
4+
5+
public record LangfuseChatPromptModel
6+
{
7+
[JsonPropertyName("name")]
8+
public required string Name { get; set; }
9+
10+
[JsonPropertyName("type")]
11+
public required string Type { get; set; }
12+
13+
[JsonPropertyName("prompt")]
14+
public required ChatMessage[] Prompt { get; set; }
15+
16+
[JsonPropertyName("config")]
17+
public LangfusePromptConfiguration? Config { get; set; }
18+
19+
[JsonPropertyName("version")]
20+
public int Version { get; set; }
21+
22+
[JsonPropertyName("labels")]
23+
public required string[] Labels { get; set; }
24+
25+
[JsonPropertyName("tags")]
26+
public required string[] Tags { get; set; }
27+
}

Options/PromptsOptions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
using PromptProvider.Models;
2+
13
namespace PromptProvider.Options;
24

35
public class PromptsOptions
46
{
5-
public Dictionary<string, string> Defaults { get; set; } = new();
7+
public Dictionary<string, string> Defaults { get; set; } = [];
8+
9+
public Dictionary<string, ChatMessage[]> ChatDefaults { get; set; } = [];
610
}

0 commit comments

Comments
 (0)