alexrozanski / LlamaChat

Chat with your favourite LLaMA models in a native macOS app
https://llamachat.app
MIT License
1.43k stars 53 forks source link

Syntax Error in ChatModel.swift #28

Closed arman-hk closed 1 year ago

arman-hk commented 1 year ago

Hey @alexrozanski, at line 73 of ChatModel.swift, you have this:

guard let lastChatContext else {
        canClearContext = false
        return
      }

It seems like a condition is missing:

      guard let _ = lastChatContext else {
        canClearContext = false
        return
      }

Shouldn't it look something like the above?

alexrozanski commented 1 year ago

@arman-hk this uses the if let shorthand introduced in Swift 5.7: https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md — functionally it's equivalent to

guard let lastChatContext = lastChatContext else {
  canClearContext = false
  return
}

as we're using the bound non-optional value of lastChatContext on line 77.

tbh this would be better written using Combine rather than in the didSet {}, I've been tweaking some of these as I've been going back through the codebase as well.

arman-hk commented 1 year ago

@alexrozanski, Thank you for clarifying the use of the shortened syntax; I wasn't aware of this new feature. looking forward to seeing the codebase improvements!