mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-17 17:16:38 +08:00
- Improve error handling across multiple middleware and adapter components, ensuring consistent error response formats in JSON. - Enhance the functionality of request conversion functions by including context parameters and robust error wrapping. - Introduce new features related to reasoning content in the messaging model, providing better customization and explanations in the documentation.
33 lines
677 B
Go
33 lines
677 B
Go
package openai
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/songquanpeng/one-api/common/logger"
|
|
"github.com/songquanpeng/one-api/relay/model"
|
|
)
|
|
|
|
func ErrorWrapper(err error, code string, statusCode int) *model.ErrorWithStatusCode {
|
|
logger.Error(context.TODO(), fmt.Sprintf("[%s]%+v", code, err))
|
|
|
|
Error := model.Error{
|
|
Message: err.Error(),
|
|
Type: "one_api_error",
|
|
Code: code,
|
|
}
|
|
return &model.ErrorWithStatusCode{
|
|
Error: Error,
|
|
StatusCode: statusCode,
|
|
}
|
|
}
|
|
|
|
func NormalizeDataLine(data string) string {
|
|
if strings.HasPrefix(data, "data:") {
|
|
content := strings.TrimLeft(data[len("data:"):], " ")
|
|
return "data: " + content
|
|
}
|
|
return data
|
|
}
|