Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Add initializer for ToolCallParam.FunctionCall #248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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