1
+ import pandas as pd
2
+
3
+ from utils import patching , PatchedCalls
4
+
5
+ @patching (
6
+ target_function = PatchedCalls .OPENAI_MODEL_LIST .value ,
7
+ data = [{'input' : {}, 'output' : {'data' : [{'id' : 'gpt-3.5-turbo-instruct' }]}}],
8
+ )
9
+ @patching (
10
+ target_function = PatchedCalls .GUIDANCE .value ,
11
+ data = [
12
+ # Responses for the first text entry
13
+ {
14
+ 'input' : {"text_" : "Apple's latest product, the iPhone 15, was released in September 2023." },
15
+ 'output' : {"predictions" : "" } # No person mentioned
16
+ },
17
+ {
18
+ 'input' : {"text_" : "Barack Obama was the 44th president of the United States." },
19
+ 'output' : {"predictions" : "Barack Obama" }
20
+ },
21
+ {
22
+ 'input' : {"text_" : "Apple's latest product, the iPhone 15, was released in September 2023." },
23
+ 'output' : {"predictions" : "iPhone 15" }
24
+ },
25
+ {
26
+ 'input' : {"text_" : "Barack Obama was the 44th president of the United States." },
27
+ 'output' : {"predictions" : "" } # No product mentioned
28
+ },
29
+ {
30
+ 'input' : {"text_" : "Apple's latest product, the iPhone 15, was released in September 2023." },
31
+ 'output' : {"predictions" : "September 2023" }
32
+ },
33
+ {
34
+ 'input' : {"text_" : "Barack Obama was the 44th president of the United States." },
35
+ 'output' : {"predictions" : "" } # No date mentioned
36
+ },
37
+ {
38
+ 'input' : {"text_" : "Apple's latest product, the iPhone 15, was released in September 2023." },
39
+ 'output' : {"predictions" : "" } # No location mentioned
40
+ },
41
+ {
42
+ 'input' : {"text_" : "Barack Obama was the 44th president of the United States." },
43
+ 'output' : {"predictions" : "United States" }
44
+ }
45
+ ],
46
+ strict = False
47
+ )
48
+ def test_llm_parallel_skillset ():
49
+ from adala .skills .skillset import ParallelSkillSet , LLMSkill
50
+ from adala .datasets import DataFrameDataset , InternalDataFrame
51
+ from adala .runtimes import OpenAIRuntime
52
+
53
+ skillset = ParallelSkillSet (
54
+ skills = [
55
+ LLMSkill (name = "skill_person" , instructions = "Extract person's name" , input_data_field = "text" ),
56
+ LLMSkill (name = "skill_product" , instructions = "Extract product name" , input_data_field = "text" ),
57
+ LLMSkill (name = "skill_date" , instructions = "Extract date" , input_data_field = "text" ),
58
+ LLMSkill (name = "skill_location" , instructions = "Extract location" , input_data_field = "text" ),
59
+ ]
60
+ )
61
+ dataset = DataFrameDataset (df = InternalDataFrame ([
62
+ "Apple's latest product, the iPhone 15, was released in September 2023." ,
63
+ "Barack Obama was the 44th president of the United States." ,
64
+ ], columns = ["text" ]))
65
+ predictions = skillset .apply (
66
+ dataset = dataset ,
67
+ runtime = OpenAIRuntime (verbose = True ),
68
+ )
69
+
70
+ pd .testing .assert_frame_equal (InternalDataFrame .from_records ([
71
+ {
72
+ 'text' : "Apple's latest product, the iPhone 15, was released in September 2023." ,
73
+ 'skill_person' : "" , # No person mentioned
74
+ 'skill_product' : 'iPhone 15' ,
75
+ 'skill_date' : 'September 2023' ,
76
+ 'skill_location' : "" # No location mentioned
77
+ },
78
+ {
79
+ 'text' : 'Barack Obama was the 44th president of the United States.' ,
80
+ 'skill_person' : 'Barack Obama' ,
81
+ 'skill_product' : "" , # No product mentioned
82
+ 'skill_date' : "" , # No date mentioned
83
+ 'skill_location' : 'United States'
84
+ }
85
+ ]), predictions )
0 commit comments