|
| 1 | +// |
| 2 | +// Copyright 2025 Formata, Inc. All rights reserved. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +// |
| 16 | + |
| 17 | + |
| 18 | +#[test] |
| 19 | +fn basic_prompt() { |
| 20 | + const prompt = <Prompt>.new('simple text'); |
| 21 | + assert_eq(prompt.out(), 'simple text'); |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +#[test] |
| 26 | +fn tagged_prompt() { |
| 27 | + const prompt = <Prompt>.new('should be tagged', tag = 'tag'); |
| 28 | + assert_eq(prompt.out(), '<tag>should be tagged</tag>'); |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +#[test] |
| 33 | +fn composed_prompts() { |
| 34 | + const arena = new {}; |
| 35 | + const prompt = <Prompt>.new(tag = 'outer', arena = arena); |
| 36 | + { |
| 37 | + prompt.push(<Prompt>.new(tag = 'person', arena = arena, |
| 38 | + prompts = [ |
| 39 | + <Prompt>.new('CJ', tag = 'first-name', arena = arena), |
| 40 | + <Prompt>.new('Cummings', tag = 'last-name', arena = arena), |
| 41 | + ] |
| 42 | + )); |
| 43 | + } |
| 44 | + { |
| 45 | + prompt.push(<ListPrompt>.new(tag = 'hobbies', arena = arena, |
| 46 | + prompts = [ |
| 47 | + <Prompt>.new('sailing', arena = arena), |
| 48 | + <Prompt>.new('dirt biking', arena = arena), |
| 49 | + <Prompt>.new('skiing', arena = arena), |
| 50 | + ] |
| 51 | + )); |
| 52 | + } |
| 53 | + const out = prompt.out(); |
| 54 | + drop(arena); |
| 55 | + assert_eq(out, "<outer><person><first-name>CJ</first-name><last-name>Cummings</last-name></person><hobbies>1. sailing\n2. dirt biking\n3. skiing\n</hobbies></outer>"); |
| 56 | +} |
| 57 | + |
| 58 | + |
| 59 | +//#[test] |
| 60 | +fn oneshot_test() { |
| 61 | + const key = ''; |
| 62 | + const prompt = <Prompt>.new('how long are dog nails on average?'); |
| 63 | + const response = await <Anthropic.Model>.oneshot(key, prompt); |
| 64 | + pln(response); |
| 65 | +} |
0 commit comments