Skip to content

Commit b9ed13a

Browse files
committed
discord fixes
1 parent 75eb043 commit b9ed13a

File tree

10 files changed

+122
-110
lines changed

10 files changed

+122
-110
lines changed

app/ui/src/components/Bot/Integration/API/APICodeGenerator.tsx

+33-39
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,33 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
import { nightOwl } from "react-syntax-highlighter/dist/cjs/styles/prism";
55
import { CopyBtn } from "../../../Common/CopyBtn";
66

7-
8-
9-
export const CodePreview: React.FC<{ code: string , lang: string}> = ({ code, lang }) => {
10-
return <div className="code relative text-base bg-gray-800 rounded-md overflow-hidden">
11-
<div className="flex items-center justify-end py-1.5 px-4">
7+
export const CodePreview: React.FC<{ code: string; lang: string }> = ({
8+
code,
9+
lang,
10+
}) => {
11+
return (
12+
<div className="code relative text-base bg-gray-800 rounded-md overflow-hidden">
13+
<div className="flex items-center justify-end py-1.5 px-4">
1214
<CopyBtn showText={false} iconSize="h-4 w-4" value={code} />
15+
</div>
16+
<SyntaxHighlighter
17+
children={String(code).replace(/\n$/, "")}
18+
style={nightOwl}
19+
key={Math.random()}
20+
showLineNumbers
21+
customStyle={{
22+
margin: 0,
23+
fontSize: "1rem",
24+
lineHeight: "1.5rem",
25+
}}
26+
language={lang}
27+
codeTagProps={{
28+
className: "text-sm",
29+
}}
30+
/>
1331
</div>
14-
<SyntaxHighlighter
15-
children={String(code).replace(/\n$/, "")}
16-
style={nightOwl}
17-
key={Math.random()}
18-
showLineNumbers
19-
customStyle={{
20-
margin: 0,
21-
fontSize: "1rem",
22-
lineHeight: "1.5rem",
23-
}}
24-
language={lang}
25-
codeTagProps={{
26-
className: "text-sm",
27-
}}
28-
/>
29-
</div>
30-
}
32+
);
33+
};
3134

3235
interface APICodeGeneratorProps {
3336
api: string;
@@ -111,40 +114,31 @@ func main() {
111114
label: (
112115
<div>
113116
<span className="text-sm font-semibold">curl</span>
114-
<img
115-
src="/code/curl.png"
116-
className=" h-4 ml-2 inline-block"
117-
/>
117+
<img src="/code/curl.png" className=" h-4 ml-2 inline-block" />
118118
</div>
119119
),
120120
key: "curl",
121-
children: <CodePreview code={codes.curlCode} lang="bash" />
121+
children: <CodePreview code={codes.curlCode} lang="bash" />,
122122
},
123123
{
124124
label: (
125125
<div>
126126
<span className="text-sm font-semibold">node</span>
127-
<img
128-
src="/code/node.png"
129-
className=" h-4 ml-2 inline-block"
130-
/>
127+
<img src="/code/node.png" className=" h-4 ml-2 inline-block" />
131128
</div>
132129
),
133130
key: "node",
134-
children: <CodePreview code={codes.nodeCode} lang="javascript" />
131+
children: <CodePreview code={codes.nodeCode} lang="javascript" />,
135132
},
136133
{
137134
label: (
138135
<div>
139136
<span className="text-sm font-semibold">python</span>
140-
<img
141-
src="/code/python.png"
142-
className="h-4 ml-2 inline-block"
143-
/>
137+
<img src="/code/python.png" className="h-4 ml-2 inline-block" />
144138
</div>
145139
),
146140
key: "python",
147-
children: <CodePreview code={codes.pythonCode} lang="python" />
141+
children: <CodePreview code={codes.pythonCode} lang="python" />,
148142
},
149143
{
150144
label: (
@@ -154,8 +148,8 @@ func main() {
154148
</div>
155149
),
156150
key: "go",
157-
children: <CodePreview code={codes.goCode} lang="go" />
158-
}
151+
children: <CodePreview code={codes.goCode} lang="go" />,
152+
},
159153
]}
160154
/>
161155
</div>

app/ui/src/components/Bot/Integration/IntegrationForm.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import api from "../../../services/api";
66
import { Link, useParams } from "react-router-dom";
77
import axios from "axios";
88
import { ClipboardIcon } from "@heroicons/react/24/outline";
9+
// import Switch from antd as AntdSwitch
10+
import { Switch as AntdSwitch } from "antd";
911

1012
//@ts-ignore
1113
function classNames(...classes) {
@@ -178,6 +180,17 @@ export const IntegrationForm: React.FC<Props> = ({ onClose, data }) => {
178180
</div>
179181
</Form.Item>
180182
);
183+
} else if (field.inputType === "boolean") {
184+
return (
185+
<Form.Item
186+
key={index}
187+
label={field.title}
188+
name={field.name}
189+
valuePropName="checked"
190+
>
191+
<AntdSwitch />
192+
</Form.Item>
193+
);
181194
}
182195

183196
return (

app/ui/src/components/Common/BotForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export const BotForm = ({
468468
className="space-y-6"
469469
initialValues={{
470470
embedding: "openai",
471-
model: "gpt-3.5-turbo",
471+
model: "gpt-3.5-turbo-dbase",
472472
maxDepth: 2,
473473
maxLinks: 10,
474474
options: {

app/ui/src/components/Dashboard/DashboardGrid.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const DashboardGrid = () => {
4444
<div className="w-full">
4545
<div className="flex items-end justify-between">
4646
<span className="text-xs lowercase text-scale-1000 text-gray-600">
47-
{bot.model}
47+
{bot.model.replace("-dbase", "")}
4848
</span>
4949
</div>
5050
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "BotIntegration" ADD COLUMN "discord_show_sources" BOOLEAN DEFAULT false,
3+
ADD COLUMN "discord_smart_label" BOOLEAN DEFAULT false;

server/prisma/schema.prisma

+13-14
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ model BotIntegration {
9797
discord_slash_command String? @default("hey")
9898
discord_slash_command_description String? @default("Use this command to get help")
9999
discord_application_id String?
100+
whatsapp_access_token String?
100101
discord_show_sources Boolean? @default(false)
101102
discord_smart_label Boolean? @default(false)
102-
whatsapp_access_token String?
103103
whatsapp_verify_token String?
104104
whatsapp_phone_number String?
105105
slack_auth_token String?
@@ -176,17 +176,16 @@ model botWebHistory {
176176
createdAt DateTime @default(now())
177177
}
178178

179-
180179
model DialoqbaseModels {
181-
id Int @id @default(autoincrement())
182-
name String?
183-
model_id String @unique
184-
model_type String @default("chat")
185-
stream_available Boolean @default(false)
186-
model_provider String?
187-
local_model Boolean @default(false)
188-
config Json @default("{}") @db.Json
189-
hide Boolean @default(false)
190-
deleted Boolean @default(false)
191-
createdAt DateTime @default(now())
192-
}
180+
id Int @id @default(autoincrement())
181+
name String?
182+
model_id String @unique
183+
model_type String @default("chat")
184+
stream_available Boolean @default(false)
185+
model_provider String?
186+
local_model Boolean @default(false)
187+
config Json @default("{}") @db.Json
188+
hide Boolean @default(false)
189+
deleted Boolean @default(false)
190+
createdAt DateTime @default(now())
191+
}

server/src/integration/discord.ts

+30-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
function url_to_label(
1717
url: string,
1818
alternative: string,
19-
smart_label: boolean,
19+
smart_label: boolean
2020
): string {
2121
// Reduce URLs to a representative label,
2222
// as Discord at most allows 80 characters in their labels
@@ -59,7 +59,7 @@ export default class DiscordBot {
5959
command: string = "hey",
6060
slashCommandsDescription: string = "Say hey to the bot",
6161
showSources: boolean | string = false,
62-
smartLabel: boolean | string = false,
62+
smartLabel: boolean | string = false
6363
) {
6464
try {
6565
if (this._clients.has(identifier)) {
@@ -81,7 +81,7 @@ export default class DiscordBot {
8181
token,
8282
clientId,
8383
slashCommands.replace(/[^a-zA-Z0-9]/g, ""),
84-
slashCommandsDescription,
84+
slashCommandsDescription
8585
);
8686
}
8787
});
@@ -114,7 +114,7 @@ export default class DiscordBot {
114114
const bot_response = await discordBotHandler(
115115
identifier,
116116
message.toString(),
117-
chat_id,
117+
chat_id
118118
);
119119

120120
const unique_button_sources: Array<string> = Array.from(
@@ -123,9 +123,9 @@ export default class DiscordBot {
123123
new Set(
124124
bot_response?.sourceDocuments?.map(
125125
(d: { metadata: { source: string } }): string =>
126-
d.metadata.source,
127-
),
128-
),
126+
d.metadata.source
127+
)
128+
)
129129
);
130130

131131
await interaction
@@ -137,24 +137,27 @@ export default class DiscordBot {
137137
description: bot_response?.text,
138138
}),
139139
],
140-
components: showSources
141-
? [
142-
new ActionRowBuilder<ButtonBuilder>({
143-
components: unique_button_sources.map(
144-
(url: string, i: number): ButtonBuilder =>
145-
new ButtonBuilder({
146-
style: ButtonStyle.Link,
147-
label: url_to_label(
148-
url,
149-
`Source ${(i + 1).toString()}`,
150-
smartLabelBool,
151-
),
152-
url: url,
153-
}),
154-
),
155-
}),
156-
]
157-
: [],
140+
components:
141+
unique_button_sources.length > 0
142+
? showSources
143+
? [
144+
new ActionRowBuilder<ButtonBuilder>({
145+
components: unique_button_sources.map(
146+
(url: string, i: number): ButtonBuilder =>
147+
new ButtonBuilder({
148+
style: ButtonStyle.Link,
149+
label: url_to_label(
150+
url,
151+
`Source ${(i + 1).toString()}`,
152+
smartLabelBool
153+
),
154+
url: url,
155+
})
156+
),
157+
}),
158+
]
159+
: []
160+
: [],
158161
})
159162
.catch((err: any) => console.log(err));
160163
}
@@ -176,7 +179,7 @@ export default class DiscordBot {
176179

177180
const bot_response = await clearDiscordChatHistory(
178181
identifier,
179-
chat_id,
182+
chat_id
180183
);
181184

182185
await reply.edit(bot_response);
@@ -212,7 +215,7 @@ export default class DiscordBot {
212215
token: string,
213216
clientId: string,
214217
slashCommands: string = "hey",
215-
slashCommandsDescription: string = "Say hey to the bot",
218+
slashCommandsDescription: string = "Say hey to the bot"
216219
) {
217220
try {
218221
const rest = new REST({ version: "10" }).setToken(token);

server/src/integration/handlers/discord.handler.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ let history = chat_history
6464
});
6565

6666
if (!modelinfo) {
67-
return "Unable to find model";
67+
return {
68+
text: "Opps! Model not found",
69+
}
6870
}
6971

7072
const botConfig = (modelinfo.config as {}) || {};

server/src/routes/api/v1/bot/integration/handlers/get.handler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function getChannelsByProvider(
117117
{
118118
name: "discord_smart_label",
119119
type: "string",
120-
inputType: "string",
120+
inputType: "boolean",
121121
title: `Smart Source Label\n("https://en.wikipedia.org/wiki/Linux_kernel" => "Linux Kernel")`,
122122
description:
123123
"Let the system try to find a smart title for every source",

0 commit comments

Comments
 (0)