55from guidance import system , user , assistant , gen
66from ..helpers import RelationshipStrategy
77import re
8-
8+ from inspect import cleandoc
99
1010class ModelSuggester (ModelerProtocol ):
1111 CONTEXT : str = """causal mechanisms"""
@@ -32,13 +32,14 @@ def suggest_domain_expertises(
3232 with system ():
3333 lm += f"""You are a helpful assistant for recommending useful domain expertises."""
3434 with user ():
35- lm + = f"""What domain expertises have the knowledge and experience needed to identify causal
35+ prompt_str = f"""What domain expertises have the knowledge and experience needed to identify causal
3636 relationships and causal influences between the { analysis_context } ? What domain expertises are needed
3737 to work with and reason about the causal influence between { factors_list } ? What domain expertises
3838 have the knowledge and experience to reason and answer questions about influence and cause between
3939 such factors? Think about this in a step by step manner and recommend { n_experts } expertises and
4040 provide each one wrapped within the tags, <domain_expertise></domain_expertise>, along with the
4141 reasoning and explanation wrapped between the tags <explanation></explanation>."""
42+ lm += cleandoc (prompt_str )
4243 with assistant ():
4344 lm += gen ("output" )
4445
@@ -74,13 +75,14 @@ def suggest_domain_experts(
7475 with system ():
7576 lm += f"""You are a helpful assistant for recommending useful domain experts."""
7677 with user ():
77- lm + = f"""What domain experts have the knowledge and experience needed to identify causal relationships
78+ prompt_str = f"""What domain experts have the knowledge and experience needed to identify causal relationships
7879 and causal influences between the { analysis_context } ? What experts are needed to work with and
7980 reason about the causal influence between { factors_list } ? What domain experts have the knowledge
8081 and experience to reason and answer questions about influence and cause between such factors? Think
8182 about this in a step by step manner and recommend { n_experts } domain experts and provide each one
8283 wrapped within the tags, <domain_expert></domain_expert>, along with the reasoning and explanation
8384 wrapped between the tags <explanation></explanation>."""
85+ lm += cleandoc (prompt_str )
8486 with assistant ():
8587 lm += gen ("output" )
8688
@@ -118,12 +120,13 @@ def suggest_stakeholders(
118120 lm += "You are a helpful assistant for recommending useful primary and secondary stakeholders."
119121
120122 with user ():
121- lm + = f"""What stakeholders have knowledge and experience in and about { analysis_context } ?
122- What stakeholders can work best with and reason well about the causal influence between
123+ prompt_str = f"""What stakeholders have knowledge and experience in and about { analysis_context } ?
124+ What stakeholders can work best with and reason well about the causal influence between
123125 { factors_list } ? What stakeholders have the knowledge and experience useful to reason within this context? Think about
124126 this in a step by step manner and recommend { n_stakeholders } stakeholders. Then provide each useful stakeholder
125127 wrapped within the tags, <stakeholder></stakeholder>, along with the reasoning and explanation wrapped between the tags
126128 <explanation></explanation>."""
129+ lm += cleandoc (prompt_str )
127130 with assistant ():
128131 lm += gen ("output" )
129132
@@ -204,13 +207,14 @@ def request_confounders(
204207 try :
205208 lm = self .llm
206209 with system ():
207- lm + = f"""You are an expert in { domain_expertise } and are studying { analysis_context } .
208- You are using your knowledge to help build a causal model that contains all the assumptions about {
210+ prompt_str = f"""You are an expert in { domain_expertise } and are studying { analysis_context } .
211+ You are using your knowledge to help build a causal model that contains all the assumptions about {
209212 analysis_context } . Where a causal model is a conceptual model that describes the causal mechanisms of a
210- system. You
211- will do this by by answering questions about cause and effect and using your domain knowledge in { domain_expertise } ."""
213+ system. You
214+ will do this by answering questions about cause and effect and using your domain knowledge in { domain_expertise } ."""
215+ lm += cleandoc (prompt_str )
212216 with user ():
213- lm + = f"""Follow the next two steps, and complete the first one before moving on to the second: (1)
217+ prompt_str = f"""Follow the next two steps, and complete the first one before moving on to the second: (1)
214218 From your perspective as an
215219 expert in { domain_expertise } , think step by step as you consider the factors that may interact between the { treatment }
216220 and the { outcome } . Use your knowlegde as an expert in { domain_expertise } to describe the confounders, if there are any
@@ -230,6 +234,7 @@ def request_confounders(
230234 <confounding_factor>factor_name</confounding_factor> where
231235 factor_name is one of the items within the factor_names list. If a factor does not have a high likelihood of directly
232236 confounding, then do not wrap the factor with any tags."""
237+ lm += cleandoc (prompt_str )
233238 with assistant ():
234239 lm += gen ("output" )
235240
@@ -284,7 +289,7 @@ def suggest_parents(
284289 lm += f"""You are an expert in { domain_expertise } and are studying { analysis_context } """
285290
286291 with user ():
287- lm + = f"""You are using your knowledge to help build a causal model that
292+ prompt_str = f"""You are using your knowledge to help build a causal model that
288293 contains all the assumptions about the factors that are directly influencing
289294 and causing the { factor } . Where a causal model is a conceptual model that describes the
290295 causal mechanisms of a system. You will do this by by answering questions about cause and
@@ -306,6 +311,7 @@ def suggest_parents(
306311{ factor } ,
307312 then do not wrap the factor with any tags. Your answer as an expert in
308313{ domain_expertise } :"""
314+ lm += cleandoc (prompt_str )
309315
310316 with assistant ():
311317 lm += gen ("output" )
@@ -349,7 +355,7 @@ def suggest_children(
349355 with system ():
350356 lm += f"""You are an expert in { domain_expertise } and are studying { analysis_context } """
351357 with user ():
352- lm + = f"""You are using your knowledge to help build a causal model that
358+ prompt_str = f"""You are using your knowledge to help build a causal model that
353359 contains all the assumptions about the factors that are directly influencing and causing the { factor } .
354360 Where a
355361 causal model is a conceptual model that describes the causal mechanisms of a system. You will do this by by
@@ -377,7 +383,7 @@ def suggest_children(
377383 factor_names list. If a factor does not have a high likelihood of directly influencing and causing the {
378384 factor } , then do not wrap the factor with any tags. Your answer as an expert in
379385 { domain_expertise } :"""
380-
386+ lm += cleandoc ( prompt_str )
381387 with assistant ():
382388 lm += gen ("output" )
383389
@@ -410,16 +416,17 @@ def suggest_pairwise_relationship(
410416 try :
411417 lm = self .llm
412418 with system ():
413- lm + = f"""You are an expert in { domain_expertise } and are
419+ prompt_str = f"""You are an expert in { domain_expertise } and are
414420 studying { analysis_context } . You are using your knowledge to help build a causal model that contains
415421 all the
416422 assumptions about { analysis_context } . Where a causal model is a conceptual model that describes the
417423 causal
418424 mechanisms of a system. You will do this by by answering questions about cause and effect and using your
419425 domain
420426 knowledge as an expert in { domain_expertise } ."""
427+ lm += cleandoc (prompt_str )
421428 with user ():
422- lm + = f"""From your perspective as an expert in { domain_expertise } , which of the following is
429+ prompt_str = f"""From your perspective as an expert in { domain_expertise } , which of the following is
423430 most likely true? (A) { factor_a } affects { factor_b } ; { factor_a } has a high likelihood of directly
424431 influencing { factor_b } ; and { factor_a } causes { factor_b } . (B) { factor_b } affects { factor_a } ;
425432 { factor_b } has a high likelihood of directly influencing { factor_a } ; and { factor_b } causes { factor_a } . (C) Neither A
@@ -429,6 +436,7 @@ def suggest_pairwise_relationship(
429436 you reach a conclusion, wrap your answer within the tags <answer></answer>. If you are done thinking, provide your
430437 answer wrapped within the tags <answer></answer>. e.g. <answer>A</answer>, <answer>B</answer>, or <answer>C</answer>.
431438 Your answer as an expert in { domain_expertise } :"""
439+ lm += cleandoc (prompt_str )
432440
433441 with assistant ():
434442 lm += gen ("output" )
0 commit comments