forked from janzaba/langfuse-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_prompt.php
More file actions
83 lines (71 loc) · 3.06 KB
/
test_prompt.php
File metadata and controls
83 lines (71 loc) · 3.06 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
75
76
77
78
79
80
81
82
83
<?php
require_once 'vendor/autoload.php';
use Langfuse\Config\Config;
use Langfuse\Client\LangfuseClient;
use Langfuse\LangfuseManager;
// Test script for prompt retrieval functionality
try {
// Initialize with your Langfuse credentials
$config = new Config([
Config::PUBLIC_KEY => 'your-public-key',
Config::SECRET_KEY => 'your-secret-key',
Config::LANGFUSE_BASE_URI => 'https://cloud.langfuse.com/',
]);
$client = new LangfuseClient($config);
$langfuse = new LangfuseManager($client);
echo "Testing Langfuse Prompt Retrieval\n";
echo "=================================\n\n";
// Example 1: Get production prompt (default)
echo "1. Getting production prompt:\n";
try {
$prompt = $langfuse->getPrompt("Extract claims from text");
echo " Name: " . $prompt->getName() . "\n";
echo " Version: " . $prompt->getVersion() . "\n";
echo " Prompt: " . substr($prompt->getPrompt(), 0, 50) . "...\n\n";
} catch (\Exception $e) {
echo " Error: " . $e->getMessage() . "\n\n";
}
// Example 2: Get prompt by label
echo "2. Getting prompt by label (production):\n";
try {
$prompt = $langfuse->getPrompt("Extract claims from text", "production");
echo " Name: " . $prompt->getName() . "\n";
echo " Version: " . $prompt->getVersion() . "\n";
echo " Prompt: " . substr($prompt->getPrompt(), 0, 50) . "...\n\n";
} catch (\Exception $e) {
echo " Error: " . $e->getMessage() . "\n\n";
}
// Example 3: Get prompt by label (latest)
echo "3. Getting prompt by label (latest):\n";
try {
$prompt = $langfuse->getPrompt("Extract claims from text", "latest");
echo " Name: " . $prompt->getName() . "\n";
echo " Version: " . $prompt->getVersion() . "\n";
echo " Prompt: " . substr($prompt->getPrompt(), 0, 50) . "...\n\n";
} catch (\Exception $e) {
echo " Error: " . $e->getMessage() . "\n\n";
}
// Example 4: Get prompt by version
echo "4. Getting prompt by version (1):\n";
try {
$prompt = $langfuse->getPrompt("Extract claims from text", null, 1);
echo " Name: " . $prompt->getName() . "\n";
echo " Version: " . $prompt->getVersion() . "\n";
echo " Prompt: " . substr($prompt->getPrompt(), 0, 50) . "...\n\n";
} catch (\Exception $e) {
echo " Error: " . $e->getMessage() . "\n\n";
}
// Example 5: Test prompt compilation with variables
echo "5. Testing prompt compilation with variables:\n";
try {
// Assuming we have a prompt with {{variable}} placeholders
$prompt = $langfuse->getPrompt("Example prompt with variables", "production");
$compiled = $prompt->compile(['name' => 'John', 'task' => 'summarization']);
echo " Compiled prompt: " . substr($compiled, 0, 100) . "...\n\n";
} catch (\Exception $e) {
echo " Error: " . $e->getMessage() . "\n\n";
}
} catch (\Exception $e) {
echo "Fatal error: " . $e->getMessage() . "\n";
}
echo "Test completed.\n";