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

Added latest models from various providers + library updates #1829

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
55 changes: 1 addition & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,12 @@ The open-source AI chat app for everyone.

View the latest demo [here](https://x.com/mckaywrigley/status/1738273242283151777?s=20).

## Updates

Hey everyone! I've heard your feedback and am working hard on a big update.

Things like simpler deployment, better backend compatibility, and improved mobile layouts are on their way.

Be back soon.

-- Mckay

## Official Hosted Version

Use Chatbot UI without having to host it yourself!

Find the official hosted version of Chatbot UI [here](https://chatbotui.com).

## Sponsor

If you find Chatbot UI useful, please consider [sponsoring](https://github.com/sponsors/mckaywrigley) me to support my open-source work :)

## Issues

We restrict "Issues" to actual issues related to the codebase.

We're getting excessive amounts of issues that amount to things like feature requests, cloud provider issues, etc.

If you are having issues with things like setup, please refer to the "Help" section in the "Discussions" tab above.

Issues unrelated to the codebase will likely be closed immediately.

## Discussions

We highly encourage you to participate in the "Discussions" tab above!

Discussions are a great place to ask questions, share ideas, and get help.

Odds are if you have a question, someone else has the same question.

## Legacy Code

Chatbot UI was recently updated to its 2.0 version.

The code for 1.0 can be found on the `legacy` branch.

## Updating

In your terminal at the root of your local Chatbot UI repository, run:

```bash
npm run update
```

If you run a hosted instance you'll also need to run:

```bash
npm run db-push
```

to apply the latest migrations to your live database.

## Local Quickstart

Expand Down Expand Up @@ -287,6 +234,6 @@ Once deployed, you should be able to use your hosted instance of Chatbot UI via

We are working on a guide for contributing.

## Contact
## Original Contributor

Message Mckay on [Twitter/X](https://twitter.com/mckaywrigley)
1 change: 0 additions & 1 deletion app/api/chat/google/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export async function POST(request: Request) {
return new Response(readableStream, {
headers: { "Content-Type": "text/plain" }
})

} catch (error: any) {
let errorMessage = error.message || "An unexpected error occurred"
const errorCode = error.status || 500
Expand Down
7 changes: 5 additions & 2 deletions components/chat/chat-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ export const handleHostedChat = async (

let draftMessages = await buildFinalMessages(payload, profile, chatImages)

let formattedMessages : any[] = []
let formattedMessages: any[] = []
if (provider === "google") {
formattedMessages = await adaptMessagesForGoogleGemini(payload, draftMessages)
formattedMessages = await adaptMessagesForGoogleGemini(
payload,
draftMessages
)
} else {
formattedMessages = draftMessages
}
Expand Down
2 changes: 1 addition & 1 deletion components/messages/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const Message: FC<MessageProps> = ({
: selectedAssistant
? selectedAssistant?.name
: MODEL_DATA?.modelName
: profile?.display_name ?? profile?.username}
: (profile?.display_name ?? profile?.username)}
</div>
</div>
)}
Expand Down
5 changes: 4 additions & 1 deletion db/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export const createFile = async (
let validFilename = fileRecord.name.replace(/[^a-z0-9.]/gi, "_").toLowerCase()
const extension = file.name.split(".").pop()
const extensionIndex = validFilename.lastIndexOf(".")
const baseName = validFilename.substring(0, (extensionIndex < 0) ? undefined : extensionIndex)
const baseName = validFilename.substring(
0,
extensionIndex < 0 ? undefined : extensionIndex
)
const maxBaseNameLength = 100 - (extension?.length || 0) - 1
if (baseName.length > maxBaseNameLength) {
fileRecord.name = baseName.substring(0, maxBaseNameLength) + "." + extension
Expand Down
54 changes: 26 additions & 28 deletions lib/build-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,36 +184,35 @@ function buildRetrievalText(fileItems: Tables<"file_items">[]) {
}

function adaptSingleMessageForGoogleGemini(message: any) {

let adaptedParts = []

let rawParts = []
if(!Array.isArray(message.content)) {
rawParts.push({type: 'text', text: message.content})
if (!Array.isArray(message.content)) {
rawParts.push({ type: "text", text: message.content })
} else {
rawParts = message.content
}

for(let i = 0; i < rawParts.length; i++) {
for (let i = 0; i < rawParts.length; i++) {
let rawPart = rawParts[i]

if(rawPart.type == 'text') {
adaptedParts.push({text: rawPart.text})
} else if(rawPart.type === 'image_url') {
if (rawPart.type == "text") {
adaptedParts.push({ text: rawPart.text })
} else if (rawPart.type === "image_url") {
adaptedParts.push({
inlineData: {
data: getBase64FromDataURL(rawPart.image_url.url),
mimeType: getMediaTypeFromDataURL(rawPart.image_url.url),
mimeType: getMediaTypeFromDataURL(rawPart.image_url.url)
}
})
}
}

let role = 'user'
if(["user", "system"].includes(message.role)) {
role = 'user'
} else if(message.role === 'assistant') {
role = 'model'
let role = "user"
if (["user", "system"].includes(message.role)) {
role = "user"
} else if (message.role === "assistant") {
role = "model"
}

return {
Expand All @@ -222,39 +221,38 @@ function adaptSingleMessageForGoogleGemini(message: any) {
}
}

function adaptMessagesForGeminiVision(
messages: any[]
) {
function adaptMessagesForGeminiVision(messages: any[]) {
// Gemini Pro Vision cannot process multiple messages
// Reformat, using all texts and last visual only

const basePrompt = messages[0].parts[0].text
const baseRole = messages[0].role
const lastMessage = messages[messages.length-1]
const visualMessageParts = lastMessage.parts;
let visualQueryMessages = [{
role: "user",
parts: [
`${baseRole}:\n${basePrompt}\n\nuser:\n${visualMessageParts[0].text}\n\n`,
visualMessageParts.slice(1)
]
}]
const lastMessage = messages[messages.length - 1]
const visualMessageParts = lastMessage.parts
let visualQueryMessages = [
{
role: "user",
parts: [
`${baseRole}:\n${basePrompt}\n\nuser:\n${visualMessageParts[0].text}\n\n`,
visualMessageParts.slice(1)
]
}
]
return visualQueryMessages
}

export async function adaptMessagesForGoogleGemini(
payload: ChatPayload,
messages: any[]
messages: any[]
) {
let geminiMessages = []
for (let i = 0; i < messages.length; i++) {
let adaptedMessage = adaptSingleMessageForGoogleGemini(messages[i])
geminiMessages.push(adaptedMessage)
}

if(payload.chatSettings.model === "gemini-pro-vision") {
if (payload.chatSettings.model === "gemini-pro-vision") {
geminiMessages = adaptMessagesForGeminiVision(geminiMessages)
}
return geminiMessages
}

68 changes: 67 additions & 1 deletion lib/chat-setting-limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ export const CHAT_SETTING_LIMITS: Record<LLMID, ChatSettingLimits> = {
},

// GOOGLE MODELS

"gemini-1.5-flash": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 8192,
MAX_CONTEXT_LENGTH: 1040384
},
"gemini-1.5-pro-exp-0801": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 8192,
MAX_CONTEXT_LENGTH: 1040384
},
"gemini-1.5-pro-latest": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
Expand Down Expand Up @@ -98,6 +104,30 @@ export const CHAT_SETTING_LIMITS: Record<LLMID, ChatSettingLimits> = {
MAX_TOKEN_OUTPUT_LENGTH: 2000,
MAX_CONTEXT_LENGTH: 32000
},
"open-mistral-nemo": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 32000
},
"codestral-mamba-2407": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 32000
},
"codestral-2405": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 32000
},
"mistral-large-2407": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 128000
},

// GROQ MODELS
"llama3-8b-8192": {
Expand All @@ -124,6 +154,36 @@ export const CHAT_SETTING_LIMITS: Record<LLMID, ChatSettingLimits> = {
MAX_TOKEN_OUTPUT_LENGTH: 8192,
MAX_CONTEXT_LENGTH: 8192
},
"llama-3.1-405b-reasoning": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 131072
},
"llama-3.1-70b-versatile": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 131072
},
"llama-3.1-8b-instant": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 131072
},
"llama3-groq-70b-8192-tool-use-preview": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 8192
},
"llama3-groq-8b-8192-tool-use-preview": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 1.0,
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 8192
},

// OPENAI MODELS
"gpt-3.5-turbo": {
Expand Down Expand Up @@ -157,6 +217,12 @@ export const CHAT_SETTING_LIMITS: Record<LLMID, ChatSettingLimits> = {
MAX_TOKEN_OUTPUT_LENGTH: 4096,
MAX_CONTEXT_LENGTH: 128000
},
"gpt-4o-mini": {
MIN_TEMPERATURE: 0.0,
MAX_TEMPERATURE: 2.0,
MAX_TOKEN_OUTPUT_LENGTH: 16384,
MAX_CONTEXT_LENGTH: 128000
},

// PERPLEXITY MODELS
"pplx-7b-online": {
Expand Down
17 changes: 16 additions & 1 deletion lib/models/llm/google-llm-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ const GEMINI_PRO_VISION: LLM = {
imageInput: true
}

export const GOOGLE_LLM_LIST: LLM[] = [GEMINI_PRO, GEMINI_PRO_VISION, GEMINI_1_5_PRO, GEMINI_1_5_FLASH]
const GEMINI_1_5_PRO_EXP0801: LLM = {
modelId: "gemini-1.5-pro-exp-0801",
modelName: "Gemini 1.5 Pro Exp 0801",
provider: "google",
hostedId: "gemini-1.5-pro-exp-0801",
platformLink: GOOGLE_PLATORM_LINK,
imageInput: true
}

export const GOOGLE_LLM_LIST: LLM[] = [
GEMINI_PRO,
GEMINI_PRO_VISION,
GEMINI_1_5_PRO,
GEMINI_1_5_FLASH,
GEMINI_1_5_PRO_EXP0801
]
Loading