fix advisor decision
This commit is contained in:
@ -8,7 +8,7 @@ from services.extractor import extract_profile, extract_passport, extract_descri
|
|||||||
from services.julius_baer_api_client import JuliusBaerApiClient
|
from services.julius_baer_api_client import JuliusBaerApiClient
|
||||||
from utils.storage.game_files_manager import store_game_round_data
|
from utils.storage.game_files_manager import store_game_round_data
|
||||||
from langchain_google_genai import ChatGoogleGenerativeAI
|
from langchain_google_genai import ChatGoogleGenerativeAI
|
||||||
from validation.llm_validate import AssistantDecision
|
from validation.llm_validate import AdvisorDecision
|
||||||
from langchain_core.prompts import ChatPromptTemplate
|
from langchain_core.prompts import ChatPromptTemplate
|
||||||
from langchain_core.output_parsers import PydanticOutputParser
|
from langchain_core.output_parsers import PydanticOutputParser
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class Advisor:
|
|||||||
is_game_running = True
|
is_game_running = True
|
||||||
while is_game_running:
|
while is_game_running:
|
||||||
payload = GameDecisionRequestDTO(
|
payload = GameDecisionRequestDTO(
|
||||||
decision=decision,
|
decision=decision.answer,
|
||||||
session_id=start_response.session_id,
|
session_id=start_response.session_id,
|
||||||
client_id=client_id,
|
client_id=client_id,
|
||||||
)
|
)
|
||||||
@ -66,15 +66,15 @@ class Advisor:
|
|||||||
# Handle first response from game initialization logic
|
# Handle first response from game initialization logic
|
||||||
if decision_counter == 0:
|
if decision_counter == 0:
|
||||||
# Store start response
|
# Store start response
|
||||||
store_game_round_data(decision, start_response, decision_counter, str(start_response.session_id) ,status)
|
store_game_round_data(decision.answer, start_response, decision_counter, str(start_response.session_id) ,status)
|
||||||
else:
|
else:
|
||||||
# store ongoing decision response
|
# store ongoing decision response
|
||||||
store_game_round_data(decision, decision_response, decision_counter, str(start_response.session_id), status)
|
store_game_round_data(decision.answer, decision_response, decision_counter, str(start_response.session_id), status)
|
||||||
|
|
||||||
decision_counter += 1
|
decision_counter += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
def make_decision(self, client_data: Dict[str, Any]) -> Literal["Accept", "Reject"]:
|
def make_decision(self, client_data: Dict[str, Any]) -> AdvisorDecision:
|
||||||
# 1. Extraction des données
|
# 1. Extraction des données
|
||||||
profile = extract_profile(client_data)
|
profile = extract_profile(client_data)
|
||||||
passport = extract_passport(client_data)
|
passport = extract_passport(client_data)
|
||||||
@ -82,7 +82,7 @@ class Advisor:
|
|||||||
account = extract_account(client_data)
|
account = extract_account(client_data)
|
||||||
|
|
||||||
# 2. Création du parser
|
# 2. Création du parser
|
||||||
parser = PydanticOutputParser(pydantic_object=AssistantDecision)
|
parser = PydanticOutputParser(pydantic_object=AdvisorDecision)
|
||||||
format_instructions = parser.get_format_instructions()
|
format_instructions = parser.get_format_instructions()
|
||||||
|
|
||||||
# 3. Prompt enrichi
|
# 3. Prompt enrichi
|
||||||
@ -130,11 +130,11 @@ class Advisor:
|
|||||||
chain = prompt | ChatGoogleGenerativeAI(model="gemini-pro") | parser
|
chain = prompt | ChatGoogleGenerativeAI(model="gemini-pro") | parser
|
||||||
|
|
||||||
# 5. Invocation
|
# 5. Invocation
|
||||||
result: AssistantDecision = chain.invoke({
|
result: AdvisorDecision = chain.invoke({
|
||||||
"passport": passport.json(),
|
"passport": passport,
|
||||||
"profile": profile.json(),
|
"profile": profile,
|
||||||
"description": description.json(),
|
"description": description,
|
||||||
"account": account.json(),
|
"account": account,
|
||||||
"format_instructions": format_instructions,
|
"format_instructions": format_instructions,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -144,4 +144,4 @@ class Advisor:
|
|||||||
else:
|
else:
|
||||||
log.info("Client accepted.")
|
log.info("Client accepted.")
|
||||||
|
|
||||||
return result.decision
|
return result
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Literal, Optional
|
from typing import Literal, Optional
|
||||||
|
|
||||||
class AssistantDecision(BaseModel):
|
class AdvisorDecision(BaseModel):
|
||||||
decision: Literal["Accept", "Reject"]
|
answer: Literal["Accept", "Reject"]
|
||||||
reason: Optional[str] = None
|
reason: Optional[str] = None
|
Reference in New Issue
Block a user