Skip to content

Conversation

@dounan
Copy link
Contributor

@dounan dounan commented Jan 26, 2025

What

Add an initializer for ToolCallParam.FunctionCall

Why

Cannot initialize without it. I have a use case that requires me to initialize a ToolCallParam (instead of using one returned by the SDK).

Affected Areas

Chat Completion API

@nezhyborets
Copy link
Collaborator

Hi @dounan , for the better understanding and thus better review, what would be such a use-case? If it can be disclosed, of course

@dounan
Copy link
Contributor Author

dounan commented Jan 29, 2025

My app talks to various LLM backends so I have an internal representation of the chat that I then map to the request format of the LLM API I need.

In order to map to the OpenAI SDK request format, I have code that looks like this:

func adapt(_ toolCall: AIResponse.ToolCall) -> ChatQuery.ChatCompletionMessageParam.AssistantMessageParam.ToolCallParam { switch toolCall { case .function(let fnToolCall): return .init( id: fnToolCall.id, function: .init( arguments: fnToolCall.argumentsJSON, name: fnToolCall.name ) ) } }

Without this PR, I cannot initialize the value of the function field . I am open to alternatives though if there is a better way.

@nezhyborets
Copy link
Collaborator

Thanks for the explanation! Let's go with this for now so that you can do what you need. With time we may gather more knowledge about related requests and maybe come up with another solution (if needed)

@nezhyborets nezhyborets merged commit 5f05c8f into MacPaw:main Jan 30, 2025
5 checks passed
@dounan dounan deleted the bug/add-initializer-to-function-call branch February 1, 2025 23:19
wangqi pushed a commit to wangqi/OpenAI that referenced this pull request Feb 18, 2025
…tion-call Bug: Add initializer for ToolCallParam.FunctionCall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants