Skip to content

Conversation API deviating from other declarations of metadata #543

@qhenkart

Description

@qhenkart

throughout the SDK, metadata is commonly represented by a shared object
https://github.com/openai/openai-[go/blob/main/shared/shared.go#L746](https://www.golinks.io/blob/main/shared/shared.go#L746?trackSource=github)

as seen here
https://github.com/openai/openai-[go/blob/main/responses/response.go#L965](https://www.golinks.io/blob/main/responses/response.go#L965?trackSource=github)

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](https://www.golinks.io/blob/main/conversations/conversation.go#L124?trackSource=github)
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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions