kevinhermawan / Ollamac

Mac app for Ollama
Other
1.33k stars 71 forks source link

Code highlighting issue ("undefined") #81

Closed pd95 closed 3 months ago

pd95 commented 3 months ago

While I was using a codellama I came across code blocks which didn't render properly. They showed only as "undefined". (example prompt: "Can you show me a Swift code snippet?")

The same prompt sent to llama3.1 showed up correctly. So I suppose the problem is due to difference in the output of codellama.

When running the prompt in terminal the difference is obvious: The code block has no language annotation.

% ollama run codellama:7b
>>> Can you show me a Swift code snippet?
Sure! Here is an example of a simple Swift code snippet:
```
let name = "Alice"
print("Hello, \(name)!")
```
This code defines a variable `name` and sets it to the string "Alice". It then uses string interpolation to print a message to the console that includes 
the value of the `name` variable.

According to my debugging the language used for the code highlighter is "" (=empty string). It should probably be nil.

A simple fix to solve this is adjusting the highlightCode() function in CodeHighlighter.swift, checking whether the language parameter is empty.

    guard language?.isEmpty == false, 
          let highlightedCode = highlightr.highlight(code, as: language)
    else {
        return Text(code)
    }