Enforce Go style rules across codebase
Apply five style rules: convert iota string enums to typed string constants, replace errors.As with errors.AsType, merge three-group imports into two groups, fix multiline parameter/argument formatting, and replace fmt.Sprintf URL construction with net/url. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -396,8 +396,8 @@ func mapError(err error) error {
|
||||
return &llm.ErrStreamingRequired{Err: err}
|
||||
}
|
||||
|
||||
var apiErr *anthropic.Error
|
||||
if !errors.As(err, &apiErr) {
|
||||
apiErr, ok := errors.AsType[*anthropic.Error](err)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -329,9 +329,8 @@ func mapStopReason(reason types.StopReason) llm.FinishReason {
|
||||
}
|
||||
|
||||
func mapError(err error) error {
|
||||
var respErr *smithyhttp.ResponseError
|
||||
if !errors.As(err, &respErr) {
|
||||
// Check for common error types by message content.
|
||||
respErr, ok := errors.AsType[*smithyhttp.ResponseError](err)
|
||||
if !ok {
|
||||
msg := err.Error()
|
||||
if strings.Contains(msg, "throttling") || strings.Contains(msg, "ThrottlingException") {
|
||||
return &llm.ErrRateLimit{Err: err}
|
||||
|
||||
@@ -206,10 +206,13 @@ func (a *StreamAccumulator) Response() *ChatCompletionResponse {
|
||||
|
||||
var parts []Part
|
||||
if thinking := a.thinking.String(); thinking != "" {
|
||||
parts = append(parts, ThinkingPart{
|
||||
Text: thinking,
|
||||
Signature: a.thinkingSignature,
|
||||
})
|
||||
parts = append(
|
||||
parts,
|
||||
ThinkingPart{
|
||||
Text: thinking,
|
||||
Signature: a.thinkingSignature,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
parts = append(parts, TextPart{Text: a.content.String()})
|
||||
|
||||
@@ -213,9 +213,10 @@ func buildMessages(messages []llm.Message) []openai.ChatCompletionMessageParamUn
|
||||
case llm.ImagePart:
|
||||
parts = append(
|
||||
parts,
|
||||
openai.ImageContentPart(openai.ChatCompletionContentPartImageImageURLParam{
|
||||
URL: p.URL,
|
||||
},
|
||||
openai.ImageContentPart(
|
||||
openai.ChatCompletionContentPartImageImageURLParam{
|
||||
URL: p.URL,
|
||||
},
|
||||
),
|
||||
)
|
||||
case llm.FilePart:
|
||||
@@ -381,8 +382,8 @@ func mapFinishReason(reason string) llm.FinishReason {
|
||||
}
|
||||
|
||||
func mapError(err error) error {
|
||||
var apiErr *openai.Error
|
||||
if !errors.As(err, &apiErr) {
|
||||
apiErr, ok := errors.AsType[*openai.Error](err)
|
||||
if !ok {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -513,9 +514,11 @@ func isReasoningModel(model string) bool {
|
||||
func buildFilePart(p llm.FilePart) openai.ChatCompletionContentPartUnionParam {
|
||||
switch {
|
||||
case strings.HasPrefix(p.MimeType, "image/"):
|
||||
return openai.ImageContentPart(openai.ChatCompletionContentPartImageImageURLParam{
|
||||
URL: fmt.Sprintf("data:%s;base64,%s", p.MimeType, p.Data),
|
||||
})
|
||||
return openai.ImageContentPart(
|
||||
openai.ChatCompletionContentPartImageImageURLParam{
|
||||
URL: fmt.Sprintf("data:%s;base64,%s", p.MimeType, p.Data),
|
||||
},
|
||||
)
|
||||
case strings.HasPrefix(p.MimeType, "text/"):
|
||||
decoded, err := base64.StdEncoding.DecodeString(p.Data)
|
||||
if err != nil {
|
||||
@@ -524,9 +527,11 @@ func buildFilePart(p llm.FilePart) openai.ChatCompletionContentPartUnionParam {
|
||||
|
||||
return openai.TextContentPart(fmt.Sprintf("File: %s\n\n%s", p.Filename, string(decoded)))
|
||||
default:
|
||||
return openai.FileContentPart(openai.ChatCompletionContentPartFileFileParam{
|
||||
FileData: param.NewOpt(fmt.Sprintf("data:%s;base64,%s", p.MimeType, p.Data)),
|
||||
Filename: param.NewOpt(p.Filename),
|
||||
})
|
||||
return openai.FileContentPart(
|
||||
openai.ChatCompletionContentPartFileFileParam{
|
||||
FileData: param.NewOpt(fmt.Sprintf("data:%s;base64,%s", p.MimeType, p.Data)),
|
||||
Filename: param.NewOpt(p.Filename),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user