
committed by
GitHub

parent
3f9de128be
commit
bc2ea68332
4
app.py
4
app.py
@ -7,6 +7,7 @@ import config
|
||||
from dto.requests import GameStartRequestDTO, GameDecisionRequestDTO
|
||||
from dto.responses import GameStartResponseWithBotDecisionDTO
|
||||
from services.julius_baer_api_client import JuliusBaerApiClient
|
||||
from services.player import Player
|
||||
|
||||
app = Flask(__name__)
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - [%(module)s] - %(message)s')
|
||||
@ -18,6 +19,7 @@ jb_client = JuliusBaerApiClient()
|
||||
def new_game():
|
||||
game_start_request = GameStartRequestDTO(player_name=config.API_TEAM)
|
||||
res = jb_client.start_game(game_start_request)
|
||||
bot_decision = Player().make_decision(res.client_data)
|
||||
|
||||
res_with_bot_decision = GameStartResponseWithBotDecisionDTO(
|
||||
message=res.message,
|
||||
@ -26,7 +28,7 @@ def new_game():
|
||||
client_id=res.client_id,
|
||||
client_data=res.client_data,
|
||||
score=res.score,
|
||||
bot_decision="Accept" # TODO: Get decision from bot
|
||||
bot_decision=bot_decision
|
||||
)
|
||||
|
||||
return res_with_bot_decision.model_dump_json()
|
||||
|
@ -1,35 +0,0 @@
|
||||
client_id,decision
|
||||
cdd60b2d-34eb-4db4-9d5e-8e903bbb4057,Accept
|
||||
7b48afa1-6db3-4762-8faf-e73b5158f6b0,Accept
|
||||
32eeffdc-91ab-4518-8dc6-4d805c5e4aed,Accept
|
||||
1b97cefc-48ab-437f-8cd0-ffd4eaa707df,Accept
|
||||
5471d561-b89b-4317-b3ed-499b5334e424,Accept
|
||||
a482b28b-6f4c-4f2d-a167-42c071a92470,Accept
|
||||
2d7d0293-291c-46ec-91fb-75351be347f8,Accept
|
||||
3006006d-1060-4b53-afd3-b702a8fc2358,Accept
|
||||
f4a42e3e-75a8-43dc-92fe-e38fe23b1d82,Accept
|
||||
a5e06a84-2b05-47d1-8149-649d7a9e8bb6,Accept
|
||||
36adf081-fef6-4696-81da-e6ba73a6c8a0,Accept
|
||||
154b3c9d-a2e0-4d40-bb39-f3a249b26bc2,Accept
|
||||
71fdff4e-466a-40c8-a944-4958be13f974,Accept
|
||||
7b20c9c6-1bd6-4675-9e46-9b9829e50252,Accept
|
||||
1591ebcd-d0c2-44c7-b130-72f9a15c8a35,Accept
|
||||
10fd6524-a2a0-4ecf-953e-6c758f7147dc,Accept
|
||||
44418b3d-e2cd-4105-a599-5165c00c4971,Accept
|
||||
06dcf9d6-3ec4-451c-9bf4-75cb9c8061ee,Accept
|
||||
d1d0eb32-9f99-422c-a404-606b4d5c3a10,Accept
|
||||
3efa6b4e-8a4b-43d8-b570-0d02dd28b5ee,Accept
|
||||
42d0b5e4-03ab-4199-a74b-2f3fbe68680a,Accept
|
||||
1ad14242-15a9-4142-bc1f-c3fdd1165021,Accept
|
||||
e11b296a-5278-49de-a6b1-01aa31a508c4,Accept
|
||||
ad6b6980-7b2e-4af9-bda0-2ec004574211,Accept
|
||||
ac62e33d-6645-4360-8e14-21bfb0b6902a,Accept
|
||||
d5789f9c-a0f4-4663-9c6e-0d416bbbffb8,Accept
|
||||
25a429d6-bd8a-45d2-af1d-a0b8e5ec2e72,Accept
|
||||
e592968f-4970-4aad-82d5-9f9383e3ae57,Accept
|
||||
ef70356d-5014-498e-9897-643b6bc88dab,Accept
|
||||
87db27e8-e1ff-4915-8dd2-2dc4afb570a4,Accept
|
||||
161cffea-a125-4496-a0fc-17d21e2ae512,Accept
|
||||
aaa05711-5e4b-455e-9971-fdba386441e9,Accept
|
||||
3709c954-6c2e-42a5-90f7-8b73c374943f,Accept
|
||||
f3054c1b-ad4a-4cad-be7b-03cb192f5c45,Accept
|
|
@ -4,8 +4,10 @@ import time
|
||||
from typing import Literal, Dict, Any
|
||||
import config
|
||||
from dto.requests import GameStartRequestDTO, GameDecisionRequestDTO
|
||||
from services.extractor import extract_profile, extract_passport, extract_description, extract_account
|
||||
from services.julius_baer_api_client import JuliusBaerApiClient
|
||||
from utils.storage.game_files_manager import store_game_round_data, store_decision
|
||||
from utils.storage.game_files_manager import store_game_round_data
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -34,10 +36,10 @@ class Player:
|
||||
start_response = self.client.start_game(payload)
|
||||
log.info('game started, session id: %s', start_response.session_id)
|
||||
|
||||
client_id = start_response.client_id
|
||||
decision = self.make_decision(start_response.client_data)
|
||||
|
||||
decision_counter = 0
|
||||
client_id = start_response.client_id
|
||||
|
||||
is_game_running = True
|
||||
while is_game_running:
|
||||
@ -53,8 +55,6 @@ class Player:
|
||||
|
||||
status = decision_response.status
|
||||
is_game_running = status not in ['gameover', 'complete']
|
||||
if is_game_running:
|
||||
store_decision(str(client_id), decision)
|
||||
client_id = decision_response.client_id
|
||||
|
||||
decision = self.make_decision(decision_response.client_data)
|
||||
@ -71,11 +71,31 @@ class Player:
|
||||
time.sleep(1)
|
||||
|
||||
def make_decision(self, client_data: Dict[str, Any]) -> Literal["Accept", "Reject"]:
|
||||
# Do your magic!
|
||||
# Data extraction
|
||||
profile = extract_profile(client_data)
|
||||
passport = extract_passport(client_data)
|
||||
description = extract_description(client_data)
|
||||
account = extract_account(client_data)
|
||||
|
||||
prompt_template = (
|
||||
"You are a helpful assistant at a private bank.\n"
|
||||
"Your task is to accept or reject a new client's application for private banking.\n\n"
|
||||
"Only reject the application if there is an inconsistency in the data provided.\n"
|
||||
"Inconsistencies include:\n"
|
||||
"- Incorrect data (e.g., mismatched or invalid information)\n"
|
||||
"- Incomplete data (e.g., missing required fields)\n\n"
|
||||
"Return only JSON matching this format:\n"
|
||||
"{format_instructions}\n\n"
|
||||
"Here is the extracted passport text:\n"
|
||||
"{processed_text}\n\n"
|
||||
"Use the extracted profile, description, and account details to check consistency."
|
||||
)
|
||||
|
||||
# You'd insert the format instructions and passport text here before calling the LLM
|
||||
# For example:
|
||||
# final_prompt = prompt_template.format(
|
||||
# format_instructions=your_format_instructions,
|
||||
# processed_text=passport['text']
|
||||
# )
|
||||
|
||||
return 'Accept' # Replace me!!
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -4,7 +4,6 @@ import logging
|
||||
import config
|
||||
import json
|
||||
from typing import Dict, Any
|
||||
import csv
|
||||
from pathlib import Path
|
||||
|
||||
from dto.responses import GameStartResponseDTO, GameDecisionResponseDTO
|
||||
@ -129,16 +128,3 @@ def store_game_round_data(decision: str, response: GameStartResponseDTO | GameDe
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"[!] Failed to save API response JSON: {e}")
|
||||
|
||||
|
||||
def store_decision(client_id: str, decision: str):
|
||||
path = Path('./resources/decision_log2.csv') # TODO clean me!!
|
||||
|
||||
path.parent.mkdir(parents=True, exist_ok=True) # create dirs if needed
|
||||
|
||||
exists = path.exists()
|
||||
with open(path, 'a', newline='') as f:
|
||||
writer = csv.writer(f)
|
||||
if not exists:
|
||||
writer.writerow(['client_id', 'decision']) # header
|
||||
writer.writerow([client_id, decision])
|
||||
|
Reference in New Issue
Block a user