Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/stages/chip_participant_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,4 +1227,4 @@ declare global {
'chip-participant-view': ChipView;
'chip-offer-form': ChipOfferForm;
}
}
}
6 changes: 4 additions & 2 deletions functions/src/api/gemini.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('Gemini API', () => {
topP: 0.9,
frequencyPenalty: 0,
presencePenalty: 0,
customRequestBodyFields: [{ name: 'seed', value: 123 }],
customRequestBodyFields: [{name: 'seed', value: 123}],
};

const response: ModelResponse = await getGeminiAPIResponse(
Expand All @@ -176,7 +176,9 @@ describe('Gemini API', () => {
generationConfig,
);

expect(response.status).toBe(ModelResponseStatus.PROVIDER_UNAVAILABLE_ERROR);
expect(response.status).toBe(
ModelResponseStatus.PROVIDER_UNAVAILABLE_ERROR,
);
expect(response.errorMessage).toContain('Service Unavailable');
});
});
4 changes: 1 addition & 3 deletions functions/src/api/gemini.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ export async function callGemini(
},
});

console.log(`DEBUG: ${JSON.stringify(response)}`);

if (response.promptFeedback) {
return {
status: ModelResponseStatus.REFUSAL_ERROR,
Expand Down Expand Up @@ -261,4 +259,4 @@ export async function getGeminiAPIResponse(
errorMessage: error.message,
};
}
}
}
31 changes: 20 additions & 11 deletions functions/src/stages/chip.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ export const requestChipAssistance = onCall(async (request) => {
// Check if participant can accept the offer (for coach mode)
const canAcceptOffer = () => {
const buyChip = Object.keys(currentOffer.buy)[0];
const participantChipMap = publicData.participantChipMap[participant.publicId] ?? {};
const participantChipMap =
publicData.participantChipMap[participant.publicId] ?? {};
const availableSell = participantChipMap[buyChip] ?? 0;
return availableSell >= currentOffer.buy[buyChip];
};
Expand All @@ -323,8 +324,9 @@ export const requestChipAssistance = onCall(async (request) => {
response = {
success: false,
modelResponse: {},
defaultMessage: "You do not have enough chips to accept this offer. So you need to reject.",
defaultReasoning: "Insufficient chips to accept the offer"
defaultMessage:
'You do not have enough chips to accept this offer. So you need to reject.',
defaultReasoning: 'Insufficient chips to accept the offer',
};
} else {
response = await getChipResponseAssistance(
Expand Down Expand Up @@ -537,23 +539,25 @@ export const selectChipAssistanceMode = onCall(async (request) => {
// Check if participant can accept the offer
const canAcceptOffer = () => {
const buyChip = Object.keys(currentOffer.buy)[0];
const participantChipMap = publicData.participantChipMap[participant.publicId] ?? {};
const participantChipMap =
publicData.participantChipMap[participant.publicId] ?? {};
const availableSell = participantChipMap[buyChip] ?? 0;
return availableSell >= currentOffer.buy[buyChip];
};

// If participant cannot accept the offer, set default response without calling LLM
if (!canAcceptOffer()) {
currentAssistance.proposedResponse = false; // auto-reject
currentAssistance.message = "You do not have enough chips to accept this offer. So you need to reject.";
currentAssistance.reasoning = "Insufficient chips to accept the offer";
currentAssistance.message =
'You do not have enough chips to accept this offer. So you need to reject.';
currentAssistance.reasoning = 'Insufficient chips to accept the offer';
currentAssistance.proposedTime = Timestamp.now();

// If delegate mode, mark as completed and actually send the reject response
if (data.assistanceMode === ChipAssistanceMode.DELEGATE) {
currentAssistance.endTime = Timestamp.now();
currentAssistance.finalResponse = false;

// Actually send the reject response to the game
await addChipResponseToPublicData(
data.experimentId,
Expand All @@ -569,7 +573,10 @@ export const selectChipAssistanceMode = onCall(async (request) => {
data.experimentId,
stage,
publicData,
await getFirestoreCohortParticipants(data.experimentId, data.cohortId),
await getFirestoreCohortParticipants(
data.experimentId,
data.cohortId,
),
participant,
participantAnswer,
await getExperimenterDataFromExperiment(data.experimentId),
Expand All @@ -579,9 +586,11 @@ export const selectChipAssistanceMode = onCall(async (request) => {
);
// If response is valid, add to current assistance
if (response.success) {
currentAssistance.proposedResponse = response.modelResponse['response'];
currentAssistance.proposedResponse =
response.modelResponse['response'];
currentAssistance.message = response.modelResponse['feedback'] ?? '';
currentAssistance.reasoning = response.modelResponse['reasoning'] ?? '';
currentAssistance.reasoning =
response.modelResponse['reasoning'] ?? '';
currentAssistance.modelResponse = response.modelResponse;
} else {
// Set error mode if response failed
Expand Down
2 changes: 1 addition & 1 deletion functions/src/stages/chip.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export async function getChipOfferAssistance(
);
}
if (responseObj) {
console.log( responseObj);
console.log(responseObj);
console.log(
`Suggested: Give ${responseObj['suggestedSellQuantity']} ${responseObj['suggestedSellType']} to get ${responseObj['suggestedBuyQuantity']} ${responseObj['suggestedBuyType']} (${responseObj['reasoning']})`,
);
Expand Down
Loading