Skip to content

Commit

Permalink
refactor: refactored LLM Providers: Adapting Modular Approach (stackb…
Browse files Browse the repository at this point in the history
…litz-labs#832)

* refactor: Refactoring Providers to have providers as modules

* updated package and lock file

* added grok model back

* updated registry system
  • Loading branch information
thecodacus authored Dec 21, 2024
1 parent 63abf52 commit 7295352
Show file tree
Hide file tree
Showing 30 changed files with 1,625 additions and 965 deletions.
3 changes: 2 additions & 1 deletion app/components/chat/BaseChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
}

initializeModelList({ apiKeys: parsedApiKeys, providerSettings }).then((modelList) => {
console.log('Model List: ', modelList);
setModelList(modelList);
});

Expand Down Expand Up @@ -359,7 +360,7 @@ export const BaseChat = React.forwardRef<HTMLDivElement, BaseChatProps>(
modelList={modelList}
provider={provider}
setProvider={setProvider}
providerList={providerList || PROVIDER_LIST}
providerList={providerList || (PROVIDER_LIST as ProviderInfo[])}
apiKeys={apiKeys}
/>
{(providerList || []).length > 0 && provider && (
Expand Down
2 changes: 1 addition & 1 deletion app/components/chat/Chat.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const ChatImpl = memo(
});
const [provider, setProvider] = useState(() => {
const savedProvider = Cookies.get('selectedProvider');
return PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER;
return (PROVIDER_LIST.find((p) => p.name === savedProvider) || DEFAULT_PROVIDER) as ProviderInfo;
});

const { showChat } = useStore(chatStore);
Expand Down
2 changes: 1 addition & 1 deletion app/components/chat/ModelSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ProviderInfo } from '~/types/model';
import type { ModelInfo } from '~/utils/types';
import { useEffect } from 'react';
import type { ModelInfo } from '~/lib/modules/llm/types';

interface ModelSelectorProps {
model?: string;
Expand Down
111 changes: 0 additions & 111 deletions app/lib/.server/llm/api-key.ts

This file was deleted.

190 changes: 0 additions & 190 deletions app/lib/.server/llm/model.ts

This file was deleted.

11 changes: 9 additions & 2 deletions app/lib/.server/llm/stream-text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { convertToCoreMessages, streamText as _streamText } from 'ai';
import { getModel } from '~/lib/.server/llm/model';
import { MAX_TOKENS } from './constants';
import { getSystemPrompt } from '~/lib/common/prompts/prompts';
import {
Expand All @@ -8,6 +7,7 @@ import {
getModelList,
MODEL_REGEX,
MODIFICATIONS_TAG_NAME,
PROVIDER_LIST,
PROVIDER_REGEX,
WORK_DIR,
} from '~/utils/constants';
Expand Down Expand Up @@ -184,6 +184,8 @@ export async function streamText(props: {

const dynamicMaxTokens = modelDetails && modelDetails.maxTokenAllowed ? modelDetails.maxTokenAllowed : MAX_TOKENS;

const provider = PROVIDER_LIST.find((p) => p.name === currentProvider) || DEFAULT_PROVIDER;

let systemPrompt =
PromptLibrary.getPropmtFromLibrary(promptId || 'default', {
cwd: WORK_DIR,
Expand All @@ -199,7 +201,12 @@ export async function streamText(props: {
}

return _streamText({
model: getModel(currentProvider, currentModel, serverEnv, apiKeys, providerSettings) as any,
model: provider.getModelInstance({
model: currentModel,
serverEnv,
apiKeys,
providerSettings,
}),
system: systemPrompt,
maxTokens: dynamicMaxTokens,
messages: convertToCoreMessages(processedMessages as any),
Expand Down
Loading

0 comments on commit 7295352

Please sign in to comment.