Skip to content

Commit e49adaa

Browse files
authored
Merge pull request #124 from danny-avila/bing-styles
Bing styles
2 parents 7015217 + 26e7a71 commit e49adaa

File tree

17 files changed

+453
-207
lines changed

17 files changed

+453
-207
lines changed

api/app/clients/bingai.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require('dotenv').config();
22
const { KeyvFile } = require('keyv-file');
33

44
const askBing = async ({ text, onProgress, convo }) => {
5-
const { BingAIClient } = (await import('@waylaidwanderer/chatgpt-api'));
5+
const { BingAIClient } = await import('@waylaidwanderer/chatgpt-api');
66

77
const bingAIClient = new BingAIClient({
88
// "_U" cookie from bing.com
@@ -11,16 +11,23 @@ const askBing = async ({ text, onProgress, convo }) => {
1111
// cookies: '',
1212
debug: false,
1313
cache: { store: new KeyvFile({ filename: './data/cache.json' }) },
14-
proxy: process.env.PROXY || null,
14+
proxy: process.env.PROXY || null
1515
});
1616

1717
let options = { onProgress };
1818
if (convo) {
1919
options = { ...options, ...convo };
2020
}
2121

22-
if (options?.jailbreakConversationId == 'false')
23-
options.jailbreakConversationId = false
22+
if (options?.jailbreakConversationId == 'false') {
23+
options.jailbreakConversationId = false;
24+
}
25+
26+
if (convo.toneStyle) {
27+
options.toneStyle = convo.toneStyle;
28+
}
29+
30+
console.log('bing options', options);
2431

2532
const res = await bingAIClient.sendMessage(text, options);
2633

api/app/clients/sydney.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const askSydney = async ({ text, onProgress, convo }) => {
2222
options = { ...options, jailbreakConversationId: convo.jailbreakConversationId, parentMessageId: convo.parentMessageId };
2323
}
2424

25+
if (convo.toneStyle) {
26+
options.toneStyle = convo.toneStyle;
27+
}
28+
2529
console.log('sydney options', options);
2630

2731
const res = await sydneyClient.sendMessage(text, options

api/models/schema/convoSchema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const convoSchema = mongoose.Schema(
3232
invocationId: {
3333
type: String
3434
},
35+
toneStyle: {
36+
type: String,
37+
default: null
38+
},
3539
chatGptLabel: {
3640
type: String,
3741
default: null

client/package-lock.json

Lines changed: 112 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@radix-ui/react-dialog": "^1.0.2",
2424
"@radix-ui/react-dropdown-menu": "^2.0.2",
2525
"@radix-ui/react-label": "^2.0.0",
26-
"@radix-ui/react-tabs": "^1.0.2",
26+
"@radix-ui/react-tabs": "^1.0.3",
2727
"@reduxjs/toolkit": "^1.9.2",
2828
"axios": "^1.3.4",
2929
"class-variance-authority": "^0.4.0",
@@ -51,6 +51,7 @@
5151
"swr": "^2.0.3",
5252
"tailwind-merge": "^1.9.1",
5353
"tailwindcss-animate": "^1.0.5",
54+
"tailwindcss-radix": "^2.8.0",
5455
"url": "^0.11.0",
5556
"uuidv4": "^6.2.13"
5657
},

client/src/components/Conversations/Conversation.jsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export default function Conversation({
2323
}) {
2424
const [renaming, setRenaming] = useState(false);
2525
const [titleInput, setTitleInput] = useState(title);
26-
const { modelMap } = useSelector((state) => state.models);
2726
const { stopStream } = useSelector((state) => state.submit);
2827
const inputRef = useRef(null);
2928
const dispatch = useDispatch();
@@ -49,7 +48,8 @@ export default function Conversation({
4948
conversationSignature,
5049
jailbreakConversationId,
5150
clientId,
52-
invocationId
51+
invocationId,
52+
toneStyle,
5353
} = bingData;
5454
dispatch(
5555
setConversation({
@@ -59,6 +59,7 @@ export default function Conversation({
5959
conversationSignature,
6060
clientId,
6161
invocationId,
62+
toneStyle,
6263
latestMessage: null
6364
})
6465
);
@@ -71,6 +72,7 @@ export default function Conversation({
7172
conversationSignature: null,
7273
clientId: null,
7374
invocationId: null,
75+
toneStyle: null,
7476
latestMessage: null
7577
})
7678
);
@@ -85,13 +87,6 @@ export default function Conversation({
8587
dispatch(setCustomModel(null));
8688
}
8789

88-
// if (modelMap[chatGptLabel.toLowerCase()]) {
89-
// console.log('custom model', chatGptLabel);
90-
// dispatch(setCustomModel(chatGptLabel.toLowerCase()));
91-
// } else {
92-
// dispatch(setCustomModel(null));
93-
// }
94-
9590
dispatch(setMessages(data));
9691
dispatch(setCustomGpt(convo));
9792
dispatch(setText(''));

client/src/components/Conversations/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default function Conversations({ conversations, conversationId, moveToTop
1414
conversationSignature: convo.conversationSignature,
1515
parentMessageId: convo.parentMessageId || null,
1616
clientId: convo.clientId,
17-
invocationId: convo.invocationId
17+
invocationId: convo.invocationId,
18+
toneStyle: convo.toneStyle,
1819
}
1920
: null;
2021

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, { useState, useEffect, forwardRef } from 'react';
2+
import { Tabs, TabsList, TabsTrigger } from '../ui/Tabs.tsx';
3+
import { useDispatch, useSelector } from 'react-redux';
4+
import { setConversation } from '~/store/convoSlice';
5+
6+
function BingStyles(props, ref) {
7+
const dispatch = useDispatch();
8+
const [value, setValue] = useState('fast');
9+
const { model } = useSelector((state) => state.submit);
10+
const { conversationId } = useSelector((state) => state.convo);
11+
const { messages } = useSelector((state) => state.messages);
12+
13+
const isBing = model === 'bingai' || model === 'sydney';
14+
useEffect(() => {
15+
if (isBing && !conversationId) {
16+
dispatch(setConversation({ toneStyle: value }));
17+
}
18+
}, [isBing, conversationId, model, value, dispatch]);
19+
20+
const show = isBing && (!conversationId || messages?.length === 0);
21+
const defaultClasses = 'p-2 rounded-md font-normal bg-white/[.60] dark:bg-gray-700 text-black';
22+
const defaultSelected = defaultClasses + 'font-medium data-[state=active]:text-white';
23+
24+
const selectedClass = (val) => val + '-tab ' + defaultSelected;
25+
26+
const changeHandler = value => {
27+
setValue(value);
28+
dispatch(setConversation({ toneStyle: value }));
29+
};
30+
return (
31+
<Tabs
32+
defaultValue={value}
33+
className={`shadow-md mb-1 bing-styles ${show ? 'show' : ''}`}
34+
onValueChange={changeHandler}
35+
ref={ref}
36+
>
37+
<TabsList className="bg-white/[.60] dark:bg-gray-700">
38+
<TabsTrigger
39+
value="creative"
40+
className={`${value === 'creative' ? selectedClass(value) : defaultClasses}`}
41+
>
42+
{'Creative'}
43+
</TabsTrigger>
44+
<TabsTrigger
45+
value="fast"
46+
className={`${value === 'fast' ? selectedClass(value) : defaultClasses}`}
47+
>
48+
{'Balanced'}
49+
</TabsTrigger>
50+
<TabsTrigger
51+
value="precise"
52+
className={`${value === 'precise' ? selectedClass(value) : defaultClasses}`}
53+
>
54+
{'Precise'}
55+
</TabsTrigger>
56+
</TabsList>
57+
</Tabs>
58+
);
59+
}
60+
61+
export default forwardRef(BingStyles);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
export default function RowButton({ onClick, children, text, className }) {
4+
return (
5+
<button
6+
onClick={onClick}
7+
className={`input-panel-button btn btn-neutral flex justify-center gap-2 border-0 md:border ${className}`}
8+
type="button"
9+
>
10+
{children}
11+
<span className="hidden md:block">{text}</span>
12+
{/* <RegenerateIcon />
13+
<span className="hidden md:block">Regenerate response</span> */}
14+
</button>
15+
);
16+
}

0 commit comments

Comments
 (0)