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

feat: add perplexity model #720

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion packages/backend/src/utils/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export async function handleStream(

res = {
choices,
citations: part.citations, // perplexity models return an array of citations links
usage: {
completion_tokens: tokens,
},
Expand Down Expand Up @@ -421,7 +422,7 @@ export async function runAImodel(
let res = await openai.chat.completions.create({
model,
messages,
stream: stream,
stream,
temperature: extra?.temperature,
max_tokens: extra?.max_tokens,
top_p: extra?.top_p,
Expand Down
37 changes: 28 additions & 9 deletions packages/frontend/components/SmartViewer/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,37 @@ function TextMessage({
}) {
const text = data.content || data.text;

return (
<Code className={classes.textMessage}>
<ProtectedText>
{editable ? (
if (editable) {
return (
<Code className={classes.textMessage}>
<ProtectedText>
<Textarea
value={data.content || data.text}
placeholder="Content"
data-testid="prompt-chat-editor"
onChange={(e) => onChange({ ...data, content: e.target.value })}
{...ghostTextAreaStyles}
/>
) : (
</ProtectedText>
</Code>
);
} else if (data.citations) {
const textWithLinks = text.replace(/\[(\d+)\]/g, (match, numberStr) => {
const idx = parseInt(numberStr, 10) - 1;
if (data.citations[idx]) {
return `<a href="${data.citations[idx]}" target="_blank" class="${classes.citationLink}">[${numberStr}]</a>`;
}
return match;
});
return (
<Code className={classes.textMessage}>
<Text size="sm" dangerouslySetInnerHTML={{ __html: textWithLinks }} />
</Code>
);
} else {
return (
<Code className={classes.textMessage}>
<ProtectedText>
<HighlightPii
text={
compact
Expand All @@ -244,10 +263,10 @@ function TextMessage({
}
piiDetection={piiDetection}
/>
)}
</ProtectedText>
</Code>
);
</ProtectedText>
</Code>
);
}
}

function ResponsiveImage({ src }) {
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/components/SmartViewer/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@
border-radius: var(--mantine-radius-sm);
width: 100%;
}


.citationLink {
text-decoration: none;;
}
2 changes: 1 addition & 1 deletion packages/frontend/components/checks/ChecksModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default function ChecksModal({
<Anchor
href="#"
onClick={() => {
$crisp.push(["do", "chat:open"]);
$crisp?.push(["do", "chat:open"]);
}}
variant="transparent"
>
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/components/layout/Empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const IntegrationStepper = ({ integration }: { integration: string }) => {
</Text>
<Button
onClick={() => {
$crisp.push(["do", "chat:open"]);
$crisp?.push(["do", "chat:open"]);
}}
size="compact-xs"
variant="outline"
Expand Down Expand Up @@ -696,7 +696,7 @@ export default function Empty({
color="blue"
variant="light"
onClick={() => {
$crisp.push(["do", "chat:open"]);
$crisp?.push(["do", "chat:open"]);
}}
>
Chat with us
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ export default function Sidebar() {
<Menu.Item
leftSection={<IconMessage2 size={14} />}
onClick={() => {
$crisp.push(["do", "chat:open"]);
$crisp?.push(["do", "chat:open"]);
}}
>
Feedback
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/pages/join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function TeamFull({ orgName }) {
component="button"
type="button"
onClick={() => {
$crisp.push(["do", "chat:open"]);
$crisp?.push(["do", "chat:open"]);
}}
>
Contact support →
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/pages/prompts/[[...id]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ function Playground() {
setTemplate({ mode: "openai" });

setOutput(run.output);

setOutputTokens(run.tokens?.completion);
}

Expand Down Expand Up @@ -358,6 +357,8 @@ function Playground() {
setOutputTokens(0);
setStreaming(true);

let citations = null;

try {
await fetcher.getStream(
`/orgs/${org?.id}/playground`,
Expand All @@ -369,8 +370,11 @@ function Playground() {
(chunk) => {
try {
const parsedLine = JSON.parse(chunk);
if (parsedLine.citations && !citations) {
citations = parsedLine.citations;
}

setOutput(parsedLine.choices[0]?.message);
setOutput({ ...parsedLine.choices[0]?.message, citations });
setOutputTokens(parsedLine.usage?.completion_tokens || 0);
setError(null);
} catch (error) {
Expand All @@ -379,6 +383,8 @@ function Playground() {
},
);

// setOutput({ ...output, citations });

// scroll template-input-area to the end
const element = document.getElementById("template-input-area");
element.scrollTop = element.scrollHeight;
Expand Down
4 changes: 3 additions & 1 deletion packages/frontend/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ function track(event: string, data?: any) {
try {
posthog?.capture(event, data);

w?.crisp?.push(["set", "session:event", [[[event, data]]]]);
if (typeof w?.crisp?.push === "function") {
w?.crisp?.push(["set", "session:event", [[[event, data]]]]);
}
} catch (e) {
console.error(e);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,9 @@ export const MODELS = [
name: "grok-2-1212",
provider: "openrouter",
},
{
id: "perplexity/llama-3.1-sonar-large-128k-online",
name: "perplexity-llama-3.1-sonar-large-128k-online",
provider: "openrouter",
},
];
Loading