anthropic.go 931 B

123456789101112131415161718192021222324252627282930313233343536
  1. package model
  2. import "github.com/labring/aiproxy/core/relay/adaptor"
  3. type AnthropicMessageRequest struct {
  4. Model string `json:"model,omitempty"`
  5. Messages []Message `json:"messages,omitempty"`
  6. }
  7. type AnthropicError struct {
  8. Type string `json:"type"`
  9. Message string `json:"message"`
  10. }
  11. type AnthropicErrorResponse struct {
  12. Type string `json:"type"`
  13. Error AnthropicError `json:"error"`
  14. }
  15. func NewAnthropicError(statusCode int, err AnthropicError) adaptor.Error {
  16. return adaptor.NewError(statusCode, AnthropicErrorResponse{
  17. Type: "error",
  18. Error: err,
  19. })
  20. }
  21. func WrapperAnthropicError(err error, typ string, statusCode int) adaptor.Error {
  22. return WrapperAnthropicErrorWithMessage(err.Error(), typ, statusCode)
  23. }
  24. func WrapperAnthropicErrorWithMessage(message, typ string, statusCode int) adaptor.Error {
  25. return NewAnthropicError(statusCode, AnthropicError{
  26. Type: typ,
  27. Message: message,
  28. })
  29. }