MCPcopy Create free account
hub / github.com/SalesforceAIResearch/perfcodegen / get_time_in_context_learning

Method get_time_in_context_learning

src/prompt.py:203–225  ·  view source on GitHub ↗
(self, history, demos = None, demo_num = 1, indicators = None)

Source from the content-addressed store, hash-verified

201 return prompts
202
203 def get_time_in_context_learning(self, history, demos = None, demo_num = 1, indicators = None):
204 if indicators == None:
205 raise ValueError("Missing indicators.")
206 if demos == None:
207 raise ValueError("Missing demos.")
208 prompts = {}
209 example = "\nOriginal Program:\n{}\n\nOptimized Program:\n{}\n"
210 demo_str = ""
211 for i in range(demo_num):
212 demo_str += example.format(demos[i][0], demos[i][1])
213
214 for prompt in history:
215 if prompt not in indicators:
216 continue
217 prompts[prompt] = []
218 for i, h in enumerate(history[prompt]):
219 if indicators[prompt][i]:
220 message = self.apply_template("time_in_context_learning", 0, {"demo": demo_str})
221 prompts[prompt].append(self.build_chat_message(message, h))
222 else:
223 prompts[prompt].append(None)
224
225 return prompts
226
227 def get_time_pre_defined_strategy(self, history, indicators = None):
228 if indicators == None:

Callers 1

get_chat_promptsMethod · 0.95

Calls 2

apply_templateMethod · 0.95
build_chat_messageMethod · 0.95

Tested by

no test coverage detected