Skip to content

Commit

Permalink
Merge pull request #45 from kalviumcommunity/enhancement/ai-evaluatio…
Browse files Browse the repository at this point in the history
…n-logic

Implement logging for validation errors and add exit conditions for the initial request batch in OpenAI evaluation
  • Loading branch information
shashanksingh2002 authored May 22, 2024
2 parents fe8ad7d + ea35606 commit 995f8f4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions services/code.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ const _executePrompt = async (
})

const validatedData = schema.validate(openAIResponse)
if (validatedData.error) {
if (validatedData.error || openAIResponse.points !== points) {
logger.error(`The response received from Open AI failed the validation check: ${validatedData}`)
++errorResponsesCount
} else {
allValidResponses.push(openAIResponse)
}
} else {
logger.error('No response received from Open AI')
++errorResponsesCount
}
})
Expand Down Expand Up @@ -337,6 +339,15 @@ const _getAiScore = async (langConfig, question, response, points, userAnswer, r
totalRequests += (5 + additionalErrorCount)
scoreConfidence = _calculateScoreConfidence(allValidResponses)
}
} else {
response.output = {
score: scoreConfidence.score,
points: scoreConfidence.points,
rationale: scoreConfidence.rationale,
confidence:
(scoreConfidence.frequency / scoreConfidence.total) * 100,
}
return
}

// Keep requesting until a high confidence score is determined, respecting the request limit
Expand All @@ -354,7 +365,7 @@ const _getAiScore = async (langConfig, question, response, points, userAnswer, r
}

if (allValidResponses.length < 10) {
throw new Error('We were not able to achieve 10 valid responses')
throw new Error('We were not able to achieve 10 valid evaluations from Open AI to generate a confidence')
}

const confidence = (scoreConfidence.frequency / scoreConfidence.total) * 100
Expand Down

0 comments on commit 995f8f4

Please sign in to comment.