Skip to content

[BREAKING_CHANGES] refactor: change metadata type from map[string]string to map[string]any - #944

Open
anilmisirlioglu wants to merge 1 commit into
sashabaranov:masterfrom
anilmisirlioglu:master
Open

[BREAKING_CHANGES] refactor: change metadata type from map[string]string to map[string]any#944
anilmisirlioglu wants to merge 1 commit into
sashabaranov:masterfrom
anilmisirlioglu:master

Conversation

@anilmisirlioglu

Copy link
Copy Markdown

Describe the change
We use Litellm and Langfuse and I realized that the map[string]string data type in the metadata field is insufficient to pass some trace fields (e.g. tags, trace_metadata) from the metadata. It is possible to make metadata type map[string]any for more complex data types. There is no statement in the OpenAI document stating that metadata must be of type map[string]string

Provide OpenAI documentation link
Litellm Langfuse Integration
OpenAI Metadata -> Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Describe your solution
I changed the type of the metadata field in ChatCompletionRequest and ModifyMessage to map[string]any

Tests
I ran the tests locally.

Issue: -

@codecov

codecov Bot commented Feb 25, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.88%. Comparing base (774fc9d) to head (37e834c).
⚠️ Report is 130 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #944      +/-   ##
==========================================
+ Coverage   98.46%   98.88%   +0.41%     
==========================================
  Files          24       27       +3     
  Lines        1364     1786     +422     
==========================================
+ Hits         1343     1766     +423     
+ Misses         15       14       -1     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lordtatty

Copy link
Copy Markdown

Hi @anilmisirlioglu, the OpenAI description for this field may have changed since you opened the PR. Looking at it now it says:

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

https://platform.openai.com/docs/api-reference/chat/create#chat-create-metadata

image

Unless I've misunderstood which metadata field this is then it looks like the keys and values both need to be strings. Are you saying that Litellm and Langfuse uses non-strings successfully for these fields?

@anilmisirlioglu

Copy link
Copy Markdown
Author

Hi, yes langfuse uses much more complex data types like the example below. It seems that the OpenAI specification has recently changed. When I opened the PR, there was no restriction that the value could be a string.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants