OpenAI icon indicating copy to clipboard operation
OpenAI copied to clipboard

Chat demo: switch message.role is not working.

Open alelordelo opened this issue 1 year ago • 3 comments

Describe the bug

On the chat demo, switch message.role is not working.

To Reproduce Steps to reproduce the behavior:

1- Change the function background color for debug purpose

var body: some View {
    HStack {
        switch message.role {
        case .assistant:
            Text(design.event)
           // Text(message.content)
                .padding(.horizontal, 16)
                .padding(.vertical, 12)
                .background(assistantBackgroundColor)
                .clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
            Spacer(minLength: 24)
        case .user:
            Spacer(minLength: 24)
            Text(message.content)
                .padding(.horizontal, 16)
                .padding(.vertical, 12)
                .foregroundColor(userForegroundColor)
                .background(userBackgroundColor)
                .clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
        case .function:
          Text(message.content)
              .font(.footnote.monospaced())
              .padding(.horizontal, 16)
              .padding(.vertical, 12)
              .background(funcBackgroundColor)
              .clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
          Spacer(minLength: 24)
        case .system:
            EmptyView()
        }
    }
}

2- Build the app, and prompt "show me weather for san Francisco!

3- The bubble will not be orange (function)

Expected behavior The bubble chat should be orange

alelordelo avatar Aug 23 '23 18:08 alelordelo

hi @Krivoblotsky , did you have a look on this? : )

alelordelo avatar Sep 13 '23 18:09 alelordelo

@Krivoblotsky , I did this as a quick fix, but would be great if this was fixed on the Package


  // Determine the role based on finishReason
                    let roleToSet: Chat.Role = (choice.finishReason == "function_call") ? .function : (choice.delta.role ?? .assistant)
                    
                    // Debugging line to print the role
                    print("Debug: choice.delta.role is \(String(describing: choice.delta.role))")

                    let message = Message(
                        id: partialChatResult.id,
                        role: roleToSet,
                        content: messageText,
                        createdAt: Date(timeIntervalSince1970: TimeInterval(partialChatResult.created))
                    )

alelordelo avatar Sep 14 '23 09:09 alelordelo

update... this actually does not work, as is sets ALL messages after a function is called, as .function

alelordelo avatar Sep 14 '23 09:09 alelordelo