Documentation
¶
Overview ¶
Package perplexity converts a universal conversation into the request Perplexity takes.
Perplexity speaks the OpenAI chat-completions schema but is stricter than OpenAI about the shape of a conversation, so this adapter embeds the OpenAI one and rewrites what it produced rather than converting the conversation a second time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TransformMessages ¶
TransformMessages rewrites the conversation to satisfy the three constraints Perplexity puts on a message history that the OpenAI schema does not:
- Only the leading run of system messages is accepted. A system message after any other message is sent as a user message instead.
- Roles must strictly alternate. Adjacent messages of the same role are merged into one carrying both their contents, which is also what the demotion above tends to produce: a system message sent as a user message next to a user message.
- The conversation must end on a user or tool message. A trailing assistant message is dropped, which is what OpenAI does with one server-side, so the turn reads the same either way.
A trailing system message is deliberately left as it is. Demoting it would make the rewrite depend on how much of the conversation has happened so far, and Perplexity keeps state within a conversation: a message sent as a user message on one turn and as a system message on the next, once more messages follow it, is rejected. A conversation of nothing but system messages is refused by the API, which reports the mistake straight away.
Types ¶
type Adapter ¶
Adapter converts a universal conversation into a Perplexity chat-completions request. The zero value is ready to use.
Messages travel under the OpenAI identifier, which the embedded adapter supplies: Perplexity reads the same message format, so a message written for one is readable by the other.
func (*Adapter) LLMInvocationParams ¶
func (a *Adapter) LLMInvocationParams( convo *frames.LLMContext, opts adapter.Options, ) (openai.Params, error)
LLMInvocationParams converts the conversation and then rewrites it to satisfy the constraints Perplexity puts on a message history.