MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / createCompletion

Method createCompletion

lib/ai.js:152–185  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

150 }
151
152 async createCompletion(messages) {
153 if (!this.isEnabled) return ''
154
155 try {
156 this.checkModel()
157 debug('Request', messages)
158
159 this.response = null
160
161 const startTime = process.hrtime()
162 const result = await generateText({
163 model: this.config.model,
164 messages,
165 })
166 const endTime = process.hrtime(startTime)
167 const executionTimeInSeconds = endTime[0] + endTime[1] / 1e9
168
169 this.response = result.text
170 this.numTokens += result.usage.totalTokens
171
172 this.totalTime += Math.round(executionTimeInSeconds)
173 debug('AI response time', executionTimeInSeconds)
174 debug('Response', this.response)
175 debug('Usage', result.usage)
176 this.stopWhenReachingTokensLimit()
177 return this.response
178 } catch (err) {
179 debug(err)
180 output.print('')
181 output.error(`AI service error: ${err.message}`)
182 this.stopWhenReachingTokensLimit()
183 return ''
184 }
185 }
186
187 async healFailedStep(failureContext) {
188 if (!this.isEnabled) return []

Callers 6

healFailedStepMethod · 0.95
generatePageObjectMethod · 0.95
writeStepsMethod · 0.95
clusterizeFunction · 0.80
analyzeFunction · 0.80
ai_test.jsFile · 0.80

Calls 3

checkModelMethod · 0.95
debugFunction · 0.85

Tested by

no test coverage detected