44
44
PromptRollout ,
45
45
create_prompt_helper ,
46
46
create_prompt_lineage_helper ,
47
+ create_prompt_variant_helper ,
47
48
get_prompt_ab_testing_helper ,
48
49
get_prompt_helper ,
50
+ get_prompt_lineage_helper ,
49
51
update_prompt_ab_testing_helper ,
50
52
)
51
53
from literalai .api .score_helpers import (
@@ -144,7 +146,6 @@ def handle_bytes(item):
144
146
145
147
146
148
class BaseLiteralAPI :
147
-
148
149
def __init__ (
149
150
self ,
150
151
api_key : Optional [str ] = None ,
@@ -201,7 +202,6 @@ class LiteralAPI(BaseLiteralAPI):
201
202
def make_gql_call (
202
203
self , description : str , query : str , variables : Dict [str , Any ]
203
204
) -> Dict :
204
-
205
205
def raise_error (error ):
206
206
logger .error (f"Failed to { description } : { error } " )
207
207
raise Exception (error )
@@ -1141,7 +1141,7 @@ def create_experiment(
1141
1141
self ,
1142
1142
name : str ,
1143
1143
dataset_id : Optional [str ] = None ,
1144
- prompt_id : Optional [str ] = None ,
1144
+ prompt_variant_id : Optional [str ] = None ,
1145
1145
params : Optional [Dict ] = None ,
1146
1146
) -> "DatasetExperiment" :
1147
1147
"""
@@ -1150,7 +1150,7 @@ def create_experiment(
1150
1150
Args:
1151
1151
name (str): The name of the experiment.
1152
1152
dataset_id (Optional[str]): The unique identifier of the dataset.
1153
- prompt_id (Optional[str]): The identifier of the prompt associated with the experiment.
1153
+ prompt_variant_id (Optional[str]): The identifier of the prompt variant to associate to the experiment.
1154
1154
params (Optional[Dict]): Additional parameters for the experiment.
1155
1155
1156
1156
Returns:
@@ -1161,7 +1161,7 @@ def create_experiment(
1161
1161
api = self ,
1162
1162
name = name ,
1163
1163
dataset_id = dataset_id ,
1164
- prompt_id = prompt_id ,
1164
+ prompt_variant_id = prompt_variant_id ,
1165
1165
params = params ,
1166
1166
)
1167
1167
)
@@ -1369,6 +1369,34 @@ def get_prompt(
1369
1369
else :
1370
1370
raise ValueError ("Either the `id` or the `name` must be provided." )
1371
1371
1372
+ def create_prompt_variant (
1373
+ self ,
1374
+ name : str ,
1375
+ template_messages : List [GenerationMessage ],
1376
+ settings : Optional [ProviderSettings ] = None ,
1377
+ tools : Optional [List [Dict ]] = None ,
1378
+ ) -> Optional [str ]:
1379
+ """
1380
+ Creates a prompt variation for an experiment.
1381
+ This variation is not an official version until manually saved.
1382
+
1383
+ Args:
1384
+ name (str): The name of the prompt to retrieve or create.
1385
+ template_messages (List[GenerationMessage]): A list of template messages for the prompt.
1386
+ settings (Optional[Dict]): Optional settings for the prompt.
1387
+ tools (Optional[List[Dict]]): Optional tool options for the model
1388
+
1389
+ Returns:
1390
+ prompt_variant_id: The prompt variant id to link with the experiment.
1391
+ """
1392
+ lineage = self .gql_helper (* get_prompt_lineage_helper (name ))
1393
+ lineage_id = lineage ["id" ] if lineage else None
1394
+ return self .gql_helper (
1395
+ * create_prompt_variant_helper (
1396
+ lineage_id , template_messages , settings , tools
1397
+ )
1398
+ )
1399
+
1372
1400
def get_prompt_ab_testing (self , name : str ) -> List [PromptRollout ]:
1373
1401
"""
1374
1402
Get the A/B testing configuration for a prompt lineage.
@@ -2351,7 +2379,7 @@ async def create_experiment(
2351
2379
self ,
2352
2380
name : str ,
2353
2381
dataset_id : Optional [str ] = None ,
2354
- prompt_id : Optional [str ] = None ,
2382
+ prompt_variant_id : Optional [str ] = None ,
2355
2383
params : Optional [Dict ] = None ,
2356
2384
) -> "DatasetExperiment" :
2357
2385
sync_api = LiteralAPI (self .api_key , self .url )
@@ -2361,7 +2389,7 @@ async def create_experiment(
2361
2389
api = sync_api ,
2362
2390
name = name ,
2363
2391
dataset_id = dataset_id ,
2364
- prompt_id = prompt_id ,
2392
+ prompt_variant_id = prompt_variant_id ,
2365
2393
params = params ,
2366
2394
)
2367
2395
)
@@ -2529,6 +2557,36 @@ async def create_prompt(
2529
2557
):
2530
2558
return await self .get_or_create_prompt (name , template_messages , settings )
2531
2559
2560
+ async def create_prompt_variant (
2561
+ self ,
2562
+ name : str ,
2563
+ template_messages : List [GenerationMessage ],
2564
+ settings : Optional [ProviderSettings ] = None ,
2565
+ tools : Optional [List [Dict ]] = None ,
2566
+ ) -> Optional [str ]:
2567
+ """
2568
+ Creates a prompt variation for an experiment.
2569
+ This variation is not an official version until manually saved.
2570
+
2571
+ Args:
2572
+ name (str): The name of the prompt to retrieve or create.
2573
+ template_messages (List[GenerationMessage]): A list of template messages for the prompt.
2574
+ settings (Optional[Dict]): Optional settings for the prompt.
2575
+ tools (Optional[List[Dict]]): Optional tool options for the model
2576
+
2577
+ Returns:
2578
+ prompt_variant_id: The prompt variant id to link with the experiment.
2579
+ """
2580
+ lineage = await self .gql_helper (* get_prompt_lineage_helper (name ))
2581
+ lineage_id = lineage ["id" ] if lineage else None
2582
+ return await self .gql_helper (
2583
+ * create_prompt_variant_helper (
2584
+ lineage_id , template_messages , settings , tools
2585
+ )
2586
+ )
2587
+
2588
+ create_prompt_variant .__doc__ = LiteralAPI .create_prompt_variant .__doc__
2589
+
2532
2590
async def get_prompt (
2533
2591
self ,
2534
2592
id : Optional [str ] = None ,
0 commit comments