MCPcopy Create free account
hub / github.com/tbphp/gpt-load / TestMultipleKeys

Method TestMultipleKeys

internal/handler/key_handler.go:329–369  ·  view source on GitHub ↗

TestMultipleKeys handles a one-off validation test for multiple keys.

(c *gin.Context)

Source from the content-addressed store, hash-verified

327
328// TestMultipleKeys handles a one-off validation test for multiple keys.
329func (s *Server) TestMultipleKeys(c *gin.Context) {
330 var req KeyTextRequest
331 if err := c.ShouldBindJSON(&req); err != nil {
332 response.Error(c, app_errors.NewAPIError(app_errors.ErrInvalidJSON, err.Error()))
333 return
334 }
335
336 groupDB, ok := s.findGroupByID(c, req.GroupID)
337 if !ok {
338 return
339 }
340
341 group, err := s.GroupManager.GetGroupByName(groupDB.Name)
342 if err != nil {
343 response.ErrorI18nFromAPIError(c, app_errors.ErrResourceNotFound, "validation.group_not_found")
344 return
345 }
346
347 if !validateKeysText(c, req.KeysText) {
348 return
349 }
350
351 start := time.Now()
352 results, err := s.KeyService.TestMultipleKeys(group, req.KeysText)
353 duration := time.Since(start).Milliseconds()
354 if err != nil {
355 if strings.Contains(err.Error(), "batch size exceeds the limit") {
356 response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error()))
357 } else if err.Error() == "no valid keys found in the input text" {
358 response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error()))
359 } else {
360 response.Error(c, app_errors.ParseDBError(err))
361 }
362 return
363 }
364
365 response.Success(c, gin.H{
366 "results": results,
367 "total_duration": duration,
368 })
369}
370
371// ValidateGroupKeys initiates a manual validation task for all keys in a group.
372func (s *Server) ValidateGroupKeys(c *gin.Context) {

Callers

nothing calls this directly

Calls 7

findGroupByIDMethod · 0.95
ErrorFunction · 0.92
ErrorI18nFromAPIErrorFunction · 0.92
SuccessFunction · 0.92
validateKeysTextFunction · 0.85
GetGroupByNameMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected