-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_prompts.go
More file actions
74 lines (63 loc) · 2.07 KB
/
api_prompts.go
File metadata and controls
74 lines (63 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package langfuse
import (
"context"
"fmt"
"net/url"
)
// --- Request types ---
// PromptsListParams configures the query for listing prompts.
type PromptsListParams struct {
Page int
Limit int
Name string
Label string
Tag string
}
// --- Response types ---
// APIPrompt represents a prompt returned by the Langfuse public API.
type APIPrompt struct {
Name string `json:"name"`
Version int `json:"version"`
Prompt any `json:"prompt"`
Type string `json:"type"` // "text" or "chat"
Config map[string]any `json:"config"`
Labels []string `json:"labels"`
Tags []string `json:"tags"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
CreatedBy string `json:"createdBy"`
ProjectID string `json:"projectId"`
}
// PromptsListResponse is the paginated response from GET /api/public/prompts.
type PromptsListResponse struct {
Data []APIPrompt `json:"data"`
Meta ListMeta `json:"meta"`
}
// --- Methods ---
// ListPrompts retrieves a paginated list of prompts.
// GET /api/public/prompts
func (c *Client) ListPrompts(ctx context.Context, p PromptsListParams) (*PromptsListResponse, error) {
v := url.Values{}
addOptionalInt(v, "page", p.Page)
addOptionalInt(v, "limit", p.Limit)
addOptionalString(v, "name", p.Name)
addOptionalString(v, "label", p.Label)
addOptionalString(v, "tag", p.Tag)
body, err := c.Get(ctx, "/api/public/v2/prompts", v)
if err != nil {
return nil, err
}
return decodeJSON[*PromptsListResponse](body)
}
// GetPrompt retrieves a specific prompt by name. Optionally filter by version or label.
// GET /api/public/v2/prompts/{promptName}
func (c *Client) GetPrompt(ctx context.Context, promptName string, version int, label string) (*APIPrompt, error) {
v := url.Values{}
addOptionalInt(v, "version", version)
addOptionalString(v, "label", label)
body, err := c.Get(ctx, fmt.Sprintf("/api/public/v2/prompts/%s", url.PathEscape(promptName)), v)
if err != nil {
return nil, err
}
return decodeJSON[*APIPrompt](body)
}