File size: 4,205 Bytes
8acb22e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from typing import List
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)
from .bidder_base import Bidder, draw_plot
from .item_base import Item
from langchain.input import get_colored_text
import time


class HumanBidder(Bidder):
    name: str
    human_name: str = "Adam"
    budget: int
    auction_hash: str
    
    cur_item_id = 0
    items: list = []
    withdraw: bool = False
    
    engagement_count: int = 0
    original_budget: int = 0
    profit: int = 0
    items_won = []
    
    all_bidders_status = {}         # track others' profit
    
    # essential for demo
    need_input: bool = False
    semaphore: int = 0              # if needs input, then semaphore is set as 1, else waits.
    input_box: str = None           # global variable for accepting user input
    
    # not used
    model_name: str = 'human'
    openai_cost = 0
    desire = ''
    plan_strategy = ''
    correct_belief = True
    
    class Config:
        arbitrary_types_allowed = True
    
    def get_plan_instruct(self, items: List[Item]):
        self.items = items
        plan_instruct = "As {bidder_name}, you have a total budget of ${budget}. This auction has a total of {item_num} items to be sequentially presented, they are:\n{items_info}".format(
            bidder_name=self.name,       
            budget=self.budget, 
            item_num=len(items), 
            items_info=self._get_items_value_str(items)
        )
        return plan_instruct
    
    def init_plan(self, plan_instruct: str):
        # Human = auctioneer, AI = bidder
        self.dialogue_history += [
            HumanMessage(content=plan_instruct),
            AIMessage(content='Got it!')
        ]
        return ''
    
    def get_bid_instruct(self, auctioneer_msg, bid_round):
        self.dialogue_history += [
            HumanMessage(content=auctioneer_msg), 
            AIMessage(content='')
        ]
        return auctioneer_msg
    
    def bid(self, bid_instruct):
        # wait for the cue to handle user input
        while self.semaphore <= 0:
            time.sleep(1)
        
        self.dialogue_history += [
            HumanMessage(content=''),
            AIMessage(content=self.input_box)
        ]
        self.semaphore -= 1
        self.need_input = False
        return self.input_box
    
    def get_summarize_instruct(self, bidding_history: str, hammer_msg: str, win_lose_msg: str):
        instruct_summarize = f"{bidding_history}\n\n{hammer_msg}\n{win_lose_msg}"
        return instruct_summarize
    
    def summarize(self, instruct_summarize: str):
        self.dialogue_history += [
            HumanMessage(content=instruct_summarize),
            AIMessage(content='Noted.')
        ]
        self.budget_history.append(self.budget)
        self.profit_history.append(self.profit)
        return ''
    
    def get_replan_instruct(self):
        return ''

    def replan(self, instruct_replan):
        self.withdraw = False
        self.cur_item_id += 1
        return ''
    
    def to_monitors(self, as_json=False):
        items_won = []
        for item, bid in self.items_won:
            items_won.append([str(item), bid, item.true_value])
        if as_json:
            return {
                'auction_hash': self.auction_hash,
                'bidder_name': self.name,
                'human_name': self.human_name,
                'model_name': self.model_name,
                'budget': self.original_budget,
                'money_left': self.budget,
                'profit': self.profit,
                'items_won': items_won,
                'engagement_count': self.engagement_count,
            }
        else:
            return [
                self.budget, 
                self.profit, 
                items_won, 
                0, 
                0, 
                round(self.failed_bid_cnt / (self.total_bid_cnt+1e-8), 2), 
                0, 
                0, 
                self.engagement_count,
                draw_plot(f"{self.name} ({self.model_name})", self.budget_history, self.profit_history), 
                [],
                [],
                [], 
                []
            ]