Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jloh02 committed Jan 20, 2024
2 parents c83212f + 5036464 commit 7e69ce0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions backend/src/chess/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ export async function llmInterpretPrompt(
}
const result = await chat.sendMessage(prompt);
const response = await result.response;

if (response.candidates[0].finishReason === FinishReason.MAX_TOKENS) {
console.log(response)
if (response.candidates && response.candidates[0].finishReason === FinishReason.MAX_TOKENS) {
return new InvalidMove(
"Blocked Prompt: The response returned was too long. Please try again."
);
} else if (response.candidates[0].finishReason === FinishReason.SAFETY) {
} else if (response.promptFeedback.blockReason === BlockReason.SAFETY) {
return new InvalidMove(
"Blocked Prompt: The prompt was flagged as harmful. Please try again."
);
} else if (response.candidates && response.candidates[0].finishReason !== FinishReason.STOP) {
return new InvalidMove(
"Invalid Prompt: Unable to generate a response from AI. Please try again."
);
}

const text = response.text();
Expand All @@ -85,7 +89,7 @@ export async function llmInterpretPrompt(
if (safe) {
return parsed;
} else {
return new InvalidMove(`Illegal Move detected: ${parsed}`);
return new InvalidMove(`Illegal Move detected: ${fen} ${parsed}`);
}
} else {
assertUnreachable(parsed);
Expand Down

0 comments on commit 7e69ce0

Please sign in to comment.