Skip to content

Commit

Permalink
Merge pull request #31 from valory-xyz/fix/prompt-template
Browse files Browse the repository at this point in the history
Fix the prompt template
  • Loading branch information
Adamantios authored Jul 28, 2023
2 parents b070173 + 7f90745 commit deb2d9b
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 32 deletions.
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dev": {
"skill/valory/market_manager_abci/0.1.0": "bafybeicfvvo7nwlq555qxi4giarng375jplpsoqymk3nxpcrvmqwz4tlwe",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihdsj4fwxfoh7hxsn7w3satykls2t5rnrl4jjkwcxxgdp5lzkdf6y",
"skill/valory/trader_abci/0.1.0": "bafybeibrtiywxhpvan5gmx5aj2heaxr7amqcuqxfmaonqjjmz6ywkwxnpq",
"skill/valory/market_manager_abci/0.1.0": "bafybeibepyfidup5up5qdpzg5vbh6f3j24gez5mcjr4gplhvhuoe62prky",
"skill/valory/decision_maker_abci/0.1.0": "bafybeieifd2eitlvmhwkuneat4iocpjq7dlzrc5v4glvd7nxnwiq4sfjii",
"skill/valory/trader_abci/0.1.0": "bafybeiczaxwev4kndfelle2fan52xtwrtnddfl4sgeuqw4u7ccf4lv2kem",
"contract/valory/market_maker/0.1.0": "bafybeig3b2wfngntdypnixi2gphuqz3o6w7zba2rq6n6kepwdmth2mx3ni",
"agent/valory/trader/0.1.0": "bafybeiawub2ykqda63ovtnt3m3wdkvqejvdebmen3wcjcfsigxhvpgmqwq",
"service/valory/trader/0.1.0": "bafybeiean2j7qg5v5t7ehtsezshps3mp7ilewl6jijuxhyukpf23tvwv5u",
"agent/valory/trader/0.1.0": "bafybeicq7nr67hf72fd7dk4qtlkmguajfvdy4ohjahfiypaltnmkkzwfpe",
"service/valory/trader/0.1.0": "bafybeiebczz6xedfnu2zzf6u2lth6uugobfdbhvhbitambsjx6ffiyikfi",
"contract/valory/erc20/0.1.0": "bafybeict775c7iytqbhiv2tq6pdwtpyzr3p2wls3duvmrl3acee7pietwy",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeifwytl5rwyleswor7rddo7lslvrsd74ikjnv5owy5cqgtrndehoye",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibfrg7vh4shxhzk5r32fhyipeahxiaz43ppz2fbbekl3x7hcpfkry",
"contract/valory/mech/0.1.0": "bafybeib3syh35usqjtqapqjjvobnkcxllkpjbxcb67g3vp3f566qsbhqgq"
},
"third_party": {
Expand Down
8 changes: 4 additions & 4 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeialcwck7fahrr23jckv5qjwg3cdq4ai2ihyjsofnbj44jzyl4cjmm
- valory/termination_abci:0.1.0:bafybeifqsogqiar4yook5bu3j6z66dbdcizey7dr3e5oxeocdjijvfbaja
- valory/transaction_settlement_abci:0.1.0:bafybeiacwr7p4nhhufoey7uz2jqkegrlykdrmc7mm3rzkvh2mslu66gyle
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifwytl5rwyleswor7rddo7lslvrsd74ikjnv5owy5cqgtrndehoye
- valory/market_manager_abci:0.1.0:bafybeicfvvo7nwlq555qxi4giarng375jplpsoqymk3nxpcrvmqwz4tlwe
- valory/decision_maker_abci:0.1.0:bafybeihdsj4fwxfoh7hxsn7w3satykls2t5rnrl4jjkwcxxgdp5lzkdf6y
- valory/trader_abci:0.1.0:bafybeibrtiywxhpvan5gmx5aj2heaxr7amqcuqxfmaonqjjmz6ywkwxnpq
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibfrg7vh4shxhzk5r32fhyipeahxiaz43ppz2fbbekl3x7hcpfkry
- valory/market_manager_abci:0.1.0:bafybeibepyfidup5up5qdpzg5vbh6f3j24gez5mcjr4gplhvhuoe62prky
- valory/decision_maker_abci:0.1.0:bafybeieifd2eitlvmhwkuneat4iocpjq7dlzrc5v4glvd7nxnwiq4sfjii
- valory/trader_abci:0.1.0:bafybeiczaxwev4kndfelle2fan52xtwrtnddfl4sgeuqw4u7ccf4lv2kem
default_ledger: ethereum
required_ledgers:
- ethereum
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeiawub2ykqda63ovtnt3m3wdkvqejvdebmen3wcjcfsigxhvpgmqwq
agent: valory/trader:0.1.0:bafybeicq7nr67hf72fd7dk4qtlkmguajfvdy4ohjahfiypaltnmkkzwfpe
number_of_agents: 4
deployment: {}
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ def _prepare_safe_tx(self) -> Generator[None, None, str]:
):
yield from self.wait_for_condition_with_sleep(step)

self.context.logger.info(
"Preparing a mutlisig transaction to place a bet for "
f"{self.synchronized_data.sampled_bet.get_outcome(self.outcome_index)!r}, "
f"with confidence {self.synchronized_data.confidence!r}, "
f"for the amount of {self.investment_amount!r}, which is equal to the amount of "
f"{self.buy_amount!r} of the corresponding conditional token."
)

return hash_payload_to_hex(
self.safe_tx_hash,
_ETHER_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def _get_request_id(self) -> WaitableConditionType:

def _get_response_hash(self) -> WaitableConditionType:
"""Get the hash of the response data."""
self.context.logger.info(
f"Filtering the mech's events from block {self.from_block} "
f"for a response to our request with id {self.request_id!r}."
)
result = yield from self._mech_contract_interact(
contract_callable="get_response",
data_key="data",
Expand All @@ -159,7 +163,7 @@ def _handle_response(
self,
res: Optional[str],
) -> Optional[Any]:
"""Handle a response from a subgraph.
"""Handle the response from the IPFS.
:param res: the response to handle.
:return: the response's result, using the given keys. `None` if response is `None` (has failed).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def setup(self) -> None:
)
prompt = self.params.prompt_template.substitute(prompt_params)
self._metadata = MechMetadata(prompt=prompt, tool=self.params.mech_tool)
msg = f"Prepared metadata {self.metadata!r} for the request."
self.context.logger.info(msg)

def _send_metadata_to_ipfs(
self,
Expand Down
14 changes: 10 additions & 4 deletions packages/valory/skills/decision_maker_abci/behaviours/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ def _set_processed(self, idx: int) -> Optional[str]:

def _sample(self) -> Tuple[Optional[str], Optional[int]]:
"""Sample a bet and return the bets, serialized, with the sampled bet marked as processed, and its index."""
bets = idx = None
available_bets = list(self.available_bets)
if len(available_bets) > 0:
idx = self._sampled_bet_idx(available_bets)
bets = self._set_processed(idx)

if len(available_bets) == 0:
msg = "There were no unprocessed bets available to sample from!"
self.context.logger.warning(msg)
return None, None

idx = self._sampled_bet_idx(available_bets)
bets = self._set_processed(idx)
msg = f"Sampled bet: {self.synchronized_data.bets[idx]}"
self.context.logger.info(msg)
return bets, idx

def async_act(self) -> Generator:
Expand Down
15 changes: 10 additions & 5 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@

RE_CONTENT_IN_BRACKETS = r"\{([^}]*)\}"
REQUIRED_BET_TEMPLATE_KEYS = {"yes", "no", "question"}
Template.delimiter = "@"


class PromptTemplate(Template):
"""A prompt template."""

delimiter = "@"


Requests = BaseRequests
Expand All @@ -64,7 +69,7 @@ def extract_keys_from_template(delimiter: str, template: str) -> Set[str]:
return set(keys)


def check_prompt_template(bet_prompt_template: Template) -> None:
def check_prompt_template(bet_prompt_template: PromptTemplate) -> None:
"""Check if the keys required for a bet are given in the provided prompt's template."""
delimiter = bet_prompt_template.delimiter
template_keys = extract_keys_from_template(delimiter, bet_prompt_template.template)
Expand Down Expand Up @@ -114,9 +119,9 @@ def ipfs_address(self) -> str:
return f"{self._ipfs_address}/"

@property
def prompt_template(self) -> Template:
"""Get the prompt template as a string `Template`."""
return Template(self._prompt_template)
def prompt_template(self) -> PromptTemplate:
"""Get the prompt template as a string `PromptTemplate`."""
return PromptTemplate(self._prompt_template)

def get_bet_amount(self, confidence: float) -> int:
"""Get the bet amount given a prediction's confidence."""
Expand Down
12 changes: 6 additions & 6 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ fingerprint:
__init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a
behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky
behaviours/base.py: bafybeig2zoyowdeqg44kyxdc5tzdiczzpkzpbchq6f2nwjqertfvmi6xvy
behaviours/bet_placement.py: bafybeigqzadqydhnu6ggsy2nznaxqghezxq2m36kasutk3awtxqc7y6gdm
behaviours/bet_placement.py: bafybeicqccffm7cuex5xofzu5cn2ink6s4kxjvvf45vvjyllgv55nwkmna
behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm
behaviours/decision_receive.py: bafybeienputxccxmraia64x73r4ogw4qzivcsketb3xmtq3xbpixrt6yca
behaviours/decision_request.py: bafybeietmihincw46ahq2kdh3ascv6htrnqzszf2uz2g6kujlu55cg5c5a
behaviours/decision_receive.py: bafybeigjct7st66x7n3go5vdp62wtdxgmgw233hyyvd3a63ly4x3ptdqbq
behaviours/decision_request.py: bafybeidsvohdt2fxonh5qmctftjj5wfaa5z3ommr2yie6e7bhcml6xueuu
behaviours/round_behaviour.py: bafybeiahjypqkswz5ufusagxpxmjhngipin2feis56lasqin75jwqcwpaa
behaviours/sampling.py: bafybeiaxhu4xa5rrk4gszmrdpiwsz37hlwwj5vtooramm4rqiyqd6sjeqm
behaviours/sampling.py: bafybeig3mdp3slye3qsstj5k6heo5ud3zr4ym7us2tvx3yqkywyoggohvm
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeickhbppg4kttuouhwagza2b3ngw3syrmceinkylcw2nruyclkb5di
handlers.py: bafybeihj33szgrcxnpd73s4nvluyxwwsvhjum2cuq3ilhhe6vfola3k7vy
models.py: bafybeiguysd4fy2apzcqtrag3yjcuat3apy5zm35blaktywjabt7pzbibu
models.py: bafybeietew6d4nva64afznxropoko2is56f33dfww5es4cmdwuqpdh56m4
payloads.py: bafybeifvklik2j2jsevy2e5oermoo3mml6hiy6gyuppsd7cgupsylosl6a
rounds.py: bafybeieynq7pvkflqrwil3o72gedqkwlmui4s5zrt3ywh7ftqxb4zvpebm
states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy
Expand All @@ -42,7 +42,7 @@ protocols:
- valory/contract_api:1.0.0:bafybeiasywsvax45qmugus5kxogejj66c5taen27h4voriodz7rgushtqa
skills:
- valory/abstract_round_abci:0.1.0:bafybeiaseziuvbzh3trjggl5hx2tv3fduqrpiwiyksudaf6nvuxmwrg74i
- valory/market_manager_abci:0.1.0:bafybeicfvvo7nwlq555qxi4giarng375jplpsoqymk3nxpcrvmqwz4tlwe
- valory/market_manager_abci:0.1.0:bafybeibepyfidup5up5qdpzg5vbh6f3j24gez5mcjr4gplhvhuoe62prky
- valory/transaction_settlement_abci:0.1.0:bafybeiacwr7p4nhhufoey7uz2jqkegrlykdrmc7mm3rzkvh2mslu66gyle
behaviours:
main:
Expand Down
2 changes: 2 additions & 0 deletions packages/valory/skills/market_manager_abci/behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def _update_bets(
if self._fetch_status != FetchStatus.SUCCESS:
self.bets = []

self.context.logger.info(f"Updated bets: {self.bets}")

def async_act(self) -> Generator:
"""Do the action."""
with self.context.benchmark_tool.measure(self.behaviour_id).local():
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/market_manager_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeie6miwn67uin3bphukmf7qgiifh4xtm42i5v3nuyqxzxtehxsqvcq
__init__.py: bafybeigrtedqzlq5mtql2ssjsdriw76ml3666m4e2c3fay6vmyzofl6v6e
behaviours.py: bafybeicl4o53f4zwwcntxui34fjhlmyrl5carz5vp5olxbeg7iltlpf7zy
behaviours.py: bafybeibe4dl5hdqpykgkgegdyhlbcbe6ftd5pzgqro3zu7oippbig75lqa
bets.py: bafybeibkmrktcj3ld5kypdjulf6gwzj6ft6qeh2iokm4yqjzzyv3ry6ga4
dialogues.py: bafybeiebofyykseqp3fmif36cqmmyf3k7d2zbocpl6t6wnlpv4szghrxbm
fsm_specification.yaml: bafybeic5cvwfbiu5pywyp3h5s2elvu7jqdrcwayay7o3v3ow47vu2jw53q
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeialcwck7fahrr23jckv5qjwg3cdq4ai2ihyjsofnbj44jzyl4cjmm
- valory/transaction_settlement_abci:0.1.0:bafybeiacwr7p4nhhufoey7uz2jqkegrlykdrmc7mm3rzkvh2mslu66gyle
- valory/termination_abci:0.1.0:bafybeifqsogqiar4yook5bu3j6z66dbdcizey7dr3e5oxeocdjijvfbaja
- valory/market_manager_abci:0.1.0:bafybeicfvvo7nwlq555qxi4giarng375jplpsoqymk3nxpcrvmqwz4tlwe
- valory/decision_maker_abci:0.1.0:bafybeihdsj4fwxfoh7hxsn7w3satykls2t5rnrl4jjkwcxxgdp5lzkdf6y
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifwytl5rwyleswor7rddo7lslvrsd74ikjnv5owy5cqgtrndehoye
- valory/market_manager_abci:0.1.0:bafybeibepyfidup5up5qdpzg5vbh6f3j24gez5mcjr4gplhvhuoe62prky
- valory/decision_maker_abci:0.1.0:bafybeieifd2eitlvmhwkuneat4iocpjq7dlzrc5v4glvd7nxnwiq4sfjii
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibfrg7vh4shxhzk5r32fhyipeahxiaz43ppz2fbbekl3x7hcpfkry
behaviours:
main:
args: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contracts: []
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeiaseziuvbzh3trjggl5hx2tv3fduqrpiwiyksudaf6nvuxmwrg74i
- valory/decision_maker_abci:0.1.0:bafybeihdsj4fwxfoh7hxsn7w3satykls2t5rnrl4jjkwcxxgdp5lzkdf6y
- valory/decision_maker_abci:0.1.0:bafybeieifd2eitlvmhwkuneat4iocpjq7dlzrc5v4glvd7nxnwiq4sfjii
behaviours:
main:
args: {}
Expand Down

0 comments on commit deb2d9b

Please sign in to comment.