Skip to content

Commit

Permalink
Working models, everything up until chat endpoint seems to run
Browse files Browse the repository at this point in the history
  • Loading branch information
KastanDay committed Jun 21, 2024
1 parent 11fc91d commit 6426832
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ export const Chat = memo(({ stopConversationRef, courseMetadata }: Props) => {
if (getCurrentPageName() != 'gpt4') {
homeDispatch({ field: 'isRetrievalLoading', value: true })
// Extract text from all user messages in the conversation
const token_limit =
OpenAIModels[selectedConversation?.model.id as OpenAIModelID].tokenLimit
// CHeck models from home context
const token_limit = selectedConversation.model.tokenLimit
// const token_limit =
// OpenAIModels[selectedConversation?.model.id as OpenAIModelID].tokenLimit

// ! DISABLE MQR FOR NOW -- too unreliable
// const useMQRetrieval = localStorage.getItem('UseMQRetrieval') === 'true'
Expand Down
3 changes: 1 addition & 2 deletions src/components/Chat/ModelSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IconChevronDown, IconExternalLink } from '@tabler/icons-react'
import { useContext } from 'react'
import { useMediaQuery } from '@mantine/hooks'
import { type OpenAIModel } from '@/types/openai'
import HomeContext from '~/pages/api/home/home.context'
import { montserrat_heading, montserrat_paragraph } from 'fonts'
import { Input, Select, Title } from '@mantine/core'
Expand Down Expand Up @@ -33,7 +32,7 @@ export const ModelSelect = React.forwardRef<HTMLDivElement, any>(
selectedConversation &&
handleUpdateConversation(selectedConversation, {
key: 'model',
value: model as OpenAIModel,
value: model,
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/pages/api/home/home.state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FolderInterface } from '@/types/folder'
import { OpenAIModel, OpenAIModelID } from '@/types/openai'
import { PluginKey } from '@/types/plugin'
import { Prompt } from '@/types/prompt'
import { SupportedModels } from '~/types/LLMProvider'

export interface HomeInitialState {
apiKey: string
Expand All @@ -12,7 +13,7 @@ export interface HomeInitialState {
lightMode: 'light' | 'dark'
messageIsStreaming: boolean
modelError: ErrorMessage | null
models: OpenAIModel[]
models: SupportedModels
selectedModel: OpenAIModel | null
folders: FolderInterface[]
conversations: Conversation[]
Expand Down
11 changes: 7 additions & 4 deletions src/pages/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

import { OpenAIModel, OpenAIModelID, OpenAIModels } from '@/types/openai'
import { decrypt, isEncrypted } from '~/utils/crypto'
import { LLMProvider, ProviderNames } from '~/types/LLMProviderKeys'
import { LLMProvider, ProviderNames } from '~/types/LLMProvider'
import { getOllamaModels } from '~/utils/modelProviders/ollama'

export const config = {
Expand Down Expand Up @@ -117,7 +117,6 @@ const handler = async (req: Request): Promise<Response> => {
return {
id: model.id,
name: OpenAIModels[value].name,
maxLength: OpenAIModels[value].maxLength,
tokenLimit: OpenAIModels[value].tokenLimit,
}
}
Expand All @@ -126,9 +125,13 @@ const handler = async (req: Request): Promise<Response> => {
})
.filter((model): model is OpenAIModel => model !== undefined)

// console.log('Final list of Models: ', models)
const finalModels = [...models, ...ollamaModels]

return new Response(JSON.stringify(models), { status: 200 })
console.log('OpenAI Models: ', models)
console.log('Ollama Models: ', ollamaModels)
console.log('FInal combined: ', finalModels)

return new Response(JSON.stringify(finalModels), { status: 200 })
} catch (error) {
console.error(error)
return new Response('Error', { status: 500 })
Expand Down
6 changes: 4 additions & 2 deletions src/types/LLMProviderKeys.ts → src/types/LLMProvider.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { OllamaModel } from './OllamaProvider'
import { OllamaModel } from '~/utils/modelProviders/ollama'
import { OpenAIModel } from './openai'

export enum ProviderNames {
Ollama = 'Ollama',
OpenAI = 'OpenAI',
}

export type SupportedModels = OllamaModel[] | OpenAIModel[]

export interface LLMProvider {
provider: ProviderNames
enabled: boolean
baseUrl: string
apiKey?: string
models?: OllamaModel[] | OpenAIModel[]
models?: SupportedModels
}
4 changes: 0 additions & 4 deletions src/types/OllamaProvider.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/types/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
export interface OpenAIModel {
id: string
name: string
maxLength: number // maximum length of a message in characters... should deprecate
tokenLimit: number
}

Expand All @@ -27,45 +26,38 @@ export const OpenAIModels: Record<OpenAIModelID, OpenAIModel> = {
[OpenAIModelID.GPT_3_5]: {
id: OpenAIModelID.GPT_3_5,
name: 'GPT-3.5 (16k)',
maxLength: 12000,
tokenLimit: 16385,
},
[OpenAIModelID.GPT_4]: {
id: OpenAIModelID.GPT_4,
name: 'GPT-4 (8k)',
maxLength: 24000,
tokenLimit: 8192,
},
[OpenAIModelID.GPT_4_Turbo]: {
id: OpenAIModelID.GPT_4_Turbo,
name: 'GPT-4 Turbo (128k)',
maxLength: 24000,
tokenLimit: 128000,
},
[OpenAIModelID.GPT_4o]: {
id: OpenAIModelID.GPT_4o,
name: 'GPT-4o (128k)',
maxLength: 24000,
tokenLimit: 128000,
},

// ! Our hard-coded Azure implementation ONLY allows GPT-4, no other azure models on that deployment
[OpenAIModelID.GPT_4_AZURE]: {
id: OpenAIModelID.GPT_4_AZURE,
name: 'GPT-4 Turbo (128k)',
maxLength: 24000,
tokenLimit: 128000,
},
[OpenAIModelID.GPT_4_HACKATHON]: {
id: OpenAIModelID.GPT_4_HACKATHON,
name: 'GPT-4 Hackathon',
maxLength: 24000,
tokenLimit: 128000,
},
[OpenAIModelID.GPT_4_AZURE_04_09]: {
id: OpenAIModelID.GPT_4_AZURE_04_09,
name: 'GPT-4 Turbo 0409 (128k)',
maxLength: 24000,
tokenLimit: 128000,
},
}
Expand Down
9 changes: 6 additions & 3 deletions src/utils/modelProviders/ollama.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
export interface OllamaModel {
id: string
name: string
parameterSize: string
tokenLimit: number
}

export const getOllamaModels = async () => {
console.log('In ollama GET endpoint')
const response = await fetch('https://ollama.ncsa.ai/api/ps')
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = await response.json()

const ollamaModels: OllamaModel[] = data.models.map((model: any) => {
return {
id: model.name,
name: model.name,
parameterSize: model.parameter_size,
parameterSize: model.details.parameter_size,
tokenLimit: 4096,
} as OllamaModel
})

Expand Down

0 comments on commit 6426832

Please sign in to comment.