openai-go
openai-go copied to clipboard
Conversation API deviating from other declarations of metadata
throughout the SDK, metadata is commonly represented by a shared object https://github.com/openai/openai-go/blob/main/shared/shared.go#L746
as seen here https://github.com/openai/openai-go/blob/main/responses/response.go#L965
And other places. This provides strict typing, shared usage and easy consumption of the SDK.
However in the conversation API, metadata is listed as any https://github.com/openai/openai-go/blob/main/conversations/conversation.go#L124 Ironically, the comment defines the exact type, but the code allows any forcing me to do type conversions like this
func toStringMap(metadata any) map[string]string {
if metadata == nil {
return nil
}
if m, ok := metadata.(map[string]string); ok {
return m
}
m := map[string]string{}
if vals, ok := metadata.(map[string]any); ok {
for k, v := range vals {
if s, ok := v.(string); ok {
m[k] = s
}
}
}
if len(m) == 0 {
return nil
}
return m
}