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

Add initializer to ChatFunctionCall to initialize from external with properties #89

Merged

Conversation

ysak-y
Copy link
Contributor

@ysak-y ysak-y commented Jul 12, 2023

What

Add initializer with properties to ChatFunctionCall struct.

Why

Because ChatFunctionCall struct doesn't have initializer with its properties, it only provides from: initializer. So I need to define function call with json format and decode it by JSONDecoder if I want to use ChatFunctionCall as follows. I think it is unusual and complicated.

let functionCallJson = """
{
    "name": "add",
    "arguments": "{\\"a\\": \\"1\\", \\"b\\": \\"1\\"}"
}
"""
do {
    if let jsonData = functionCallJson.data(using: .utf8) {
        let chat = Chat(role: .assistant, content: nil, functionCall: try JSONDecoder().decode(ChatFunctionCall.self, from: jsonData))
    }
} catch {
    print(error)
}

I can initialize it more simply by implementing initializer with properties for it. So I want to add initializer with properties to ChatFunctionCall. I think it is usual flow for initializing struct.

let functionCall = ChatFunctionCall(name: "add", arguments: "{\"a\": \"1\", \"b\": \"1\"}")
let chat = Chat(role: .assistant, content: nil, functionCall: functionCall)

Affected Areas

ChatFunctionCall struct.

@sonarcloud
Copy link

sonarcloud bot commented Aug 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Collaborator

@Krivoblotsky Krivoblotsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Krivoblotsky Krivoblotsky merged commit c45f332 into MacPaw:main Aug 22, 2023
5 checks passed
@alelordelo
Copy link

@ysak-y , did find a way to render the function as “.function” in the chat bubble? Currently it’s wrongly rendered as “.assistant”

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.

None yet

3 participants