Skip to content

Commit

Permalink
Merge pull request #20 from 0xPlaygrounds/fix(perplexity)/completion-…
Browse files Browse the repository at this point in the history
…request

fix(perplexity): fix preamble and context in completion request
  • Loading branch information
cvauclair authored Sep 16, 2024
2 parents 8ddf8c6 + 5e6e582 commit b998107
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions rig-core/src/providers/perplexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,33 @@ impl completion::CompletionModel for CompletionModel {
&self,
completion_request: completion::CompletionRequest,
) -> Result<completion::CompletionResponse<CompletionResponse>, CompletionError> {
let mut messages = completion_request.chat_history.clone();
if let Some(preamble) = completion_request.preamble {
messages.push(completion::Message {
role: "system".to_string(),
content: preamble,
});
}
// Add preamble to messages (if available)
let mut messages = if let Some(preamble) = &completion_request.preamble {
vec![completion::Message {
role: "system".into(),
content: preamble.clone(),
}]
} else {
vec![]
};

// Add context documents to chat history
messages.append(
completion_request
.documents
.into_iter()
.map(|doc| completion::Message {
role: "system".into(),
content: serde_json::to_string(&doc).expect("Document should serialize"),
})
.collect::<Vec<_>>()
.as_mut(),
);

// Add chat history to messages
messages.extend(completion_request.chat_history);

// Add user prompt to messages
messages.push(completion::Message {
role: "user".to_string(),
content: completion_request.prompt,
Expand Down

0 comments on commit b998107

Please sign in to comment.