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:
Émile Ré
2026-05-20 11:46:39 +04:00
parent 34c25c2727
commit f5703d390b
105 changed files with 1180 additions and 940 deletions

View File

@@ -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),
},
)
}
}