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

Adds support for perplexity citations #34

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates chat generating after done, prevent processing when not relev…
…ant.
  • Loading branch information
regismesquita committed Dec 17, 2024
commit 495174eb82b8d7678f46a34b92cdd62e74e6c3ca
15 changes: 9 additions & 6 deletions macai/Utilities/APIHandlers/PerplexityHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PerplexityHandler: APIService {
else {
completion(.failure(.invalidResponse))
}
self.isGeneratingChatName = false

case .failure(let error):
completion(.failure(error))
Expand Down Expand Up @@ -189,12 +190,14 @@ class PerplexityHandler: APIService {
guard let citations = citations, !isGeneratingChatName else { return content }

var formattedContent = content
for (index, citation) in citations.enumerated() {
let reference = "[\(index + 1)]"
formattedContent = formattedContent.replacingOccurrences(
of: reference,
with: "[\\[\(index + 1)\\]](\(citation))"
)
if formattedContent.contains("[") {
for (index, citation) in citations.enumerated() {
let reference = "[\(index + 1)]"
formattedContent = formattedContent.replacingOccurrences(
of: reference,
with: "[\\[\(index + 1)\\]](\(citation))"
)
}
}
return formattedContent
}
Expand Down