|
1 | | -// Test script for the simplified proxy approach |
| 1 | +// Experimental upcoming beta AI primitve. |
| 2 | +// Please refer to the documentation for more information: https://langbase.com/docs for more information. |
| 3 | + |
2 | 4 | import 'dotenv/config'; |
3 | | -import {Langbase} from 'langbase'; |
| 5 | +import {Langbase, Workflow} from 'langbase'; |
4 | 6 |
|
5 | | -// Create Langbase instance |
6 | 7 | const langbase = new Langbase({ |
7 | 8 | apiKey: process.env.LANGBASE_API_KEY!, |
8 | 9 | }); |
9 | 10 |
|
10 | 11 | async function main() { |
11 | | - // Create a workflow with debug mode enabled |
12 | | - const workflow = langbase.workflow({ |
13 | | - name: 'simplified-proxy-test', |
14 | | - debug: true, // Enable debug logging |
| 12 | + const {step} = new Workflow({debug: true}); |
| 13 | + |
| 14 | + const result = await step({ |
| 15 | + id: 'sumamrize', |
| 16 | + run: async () => { |
| 17 | + return langbase.llm.run({ |
| 18 | + model: 'openai:gpt-4o-mini', |
| 19 | + apiKey: process.env.OPENAI_API_KEY!, |
| 20 | + messages: [ |
| 21 | + { |
| 22 | + role: 'system', |
| 23 | + content: |
| 24 | + 'You are an expert summarizer. Summarize the user input.', |
| 25 | + }, |
| 26 | + { |
| 27 | + role: 'user', |
| 28 | + content: |
| 29 | + 'I am testing workflows. I just created an example of summarize workflow. Can you summarize this?', |
| 30 | + }, |
| 31 | + ], |
| 32 | + stream: false, |
| 33 | + }); |
| 34 | + }, |
15 | 35 | }); |
16 | 36 |
|
17 | | - try { |
18 | | - // STEP 1: Call langbase.agent.run but don't return its result directly |
19 | | - const step1Result = await workflow.step({ |
20 | | - id: 'call-but-return-custom', |
21 | | - run: async () => { |
22 | | - // Return custom result instead |
23 | | - return { |
24 | | - customField: 'Custom result from simplified proxy', |
25 | | - timestamp: new Date().toISOString(), |
26 | | - }; |
27 | | - }, |
28 | | - }); |
29 | | - |
30 | | - // STEP 2: Return agent.run result directly |
31 | | - const step2Result = await workflow.step({ |
32 | | - id: 'return-agent-run-directly', |
33 | | - run: async () => { |
34 | | - // Call Langbase API and return the result directly |
35 | | - return langbase.agent.run({ |
36 | | - model: 'openai:gpt-4o-mini', |
37 | | - apiKey: process.env.OPENAI_API_KEY!, |
38 | | - instructions: 'Be brief and concise.', |
39 | | - input: 'What is 2+2?', |
40 | | - stream: false, |
41 | | - }); |
42 | | - }, |
43 | | - }); |
44 | | - |
45 | | - // STEP 3: Make multiple Langbase calls in one step |
46 | | - const step3Result = await workflow.step({ |
47 | | - id: 'multiple-calls', |
48 | | - run: async () => { |
49 | | - // First call |
50 | | - const call1 = await langbase.agent.run({ |
51 | | - model: 'openai:gpt-4o-mini', |
52 | | - apiKey: process.env.OPENAI_API_KEY!, |
53 | | - instructions: 'Be brief.', |
54 | | - input: 'First proxy test', |
55 | | - stream: false, |
56 | | - }); |
57 | | - |
58 | | - // Second call with different method |
59 | | - const call2 = await langbase.agent.run({ |
60 | | - model: 'openai:gpt-4o-mini', |
61 | | - apiKey: process.env.OPENAI_API_KEY!, |
62 | | - instructions: 'Be brief.', |
63 | | - input: 'Second proxy test', |
64 | | - stream: false, |
65 | | - }); |
66 | | - |
67 | | - // Return combined result |
68 | | - return { |
69 | | - summary: 'Multiple calls completed with simplified proxy', |
70 | | - calls: 2, |
71 | | - firstOutput: call1.output, |
72 | | - secondOutput: call2.output, |
73 | | - }; |
74 | | - }, |
75 | | - }); |
76 | | - } catch (error) { |
77 | | - console.error('❌ Workflow error:', error); |
78 | | - } finally { |
79 | | - // End the workflow to show trace report |
80 | | - workflow.end(); |
81 | | - } |
| 37 | + console.log(result['completion']); |
82 | 38 | } |
83 | 39 |
|
84 | | -// Run the test |
85 | | -main().catch(console.error); |
| 40 | +main(); |
0 commit comments