Skip to content

Commit

Permalink
WIP: Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimpson committed Nov 21, 2024
1 parent fe3e2eb commit 4306432
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/components/chat/APIKeyManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface APIKeyManagerProps {
labelForGetApiKey?: string;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export const APIKeyManager: React.FC<APIKeyManagerProps> = ({ provider, apiKey, setApiKey }) => {
const [isEditing, setIsEditing] = useState(false);
const [tempKey, setTempKey] = useState(apiKey);
Expand Down
9 changes: 6 additions & 3 deletions app/components/chat/BaseChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Menu } from '~/components/sidebar/Menu.client';
import { IconButton } from '~/components/ui/IconButton';
import { Workbench } from '~/components/workbench/Workbench.client';
import { classNames } from '~/utils/classNames';
import { MODEL_LIST, DEFAULT_PROVIDER, PROVIDER_LIST, initializeModelList } from '~/utils/constants';
import { MODEL_LIST, PROVIDER_LIST, initializeModelList } from '~/utils/constants';
import { Messages } from './Messages.client';
import { SendButton } from './SendButton.client';
import { useState } from 'react';
Expand All @@ -27,22 +27,25 @@ const EXAMPLE_PROMPTS = [
{ text: 'How do I center a div?' },
];

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const providerList = PROVIDER_LIST;

// @ts-ignore TODO: Introduce proper types
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const ModelSelector = ({ model, setModel, provider, setProvider, modelList, providerList, apiKeys }) => {
return (
<div className="mb-2 flex gap-2 flex-col sm:flex-row">
<select
value={provider?.name}
onChange={(e) => {
setProvider(providerList.find((p) => p.name === e.target.value));
setProvider(providerList.find((p: ProviderInfo) => p.name === e.target.value));

const firstModel = [...modelList].find((m) => m.provider == e.target.value);
setModel(firstModel ? firstModel.name : '');
}}
className="flex-1 p-2 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary focus:outline-none focus:ring-2 focus:ring-bolt-elements-focus transition-all"
>
{providerList.map((provider) => (
{providerList.map((provider: ProviderInfo) => (
<option key={provider.name} value={provider.name}>
{provider.name}
</option>
Expand Down
1 change: 0 additions & 1 deletion app/components/sidebar/Menu.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { motion, type Variants } from 'framer-motion';
import { useCallback, useEffect, useRef, useState } from 'react';
import { toast } from 'react-toastify';
import { Dialog, DialogButton, DialogDescription, DialogRoot, DialogTitle } from '~/components/ui/Dialog';
import { IconButton } from '~/components/ui/IconButton';
import { ThemeSwitch } from '~/components/ui/ThemeSwitch';
import { db, deleteById, getAll, chatId, type ChatHistoryItem, useChatHistory } from '~/lib/persistence';
import { cubicEasingFn } from '~/utils/easings';
Expand Down
3 changes: 2 additions & 1 deletion app/lib/.server/llm/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ export function getBaseURL(cloudflareEnv: Env, provider: string) {
return env.OPENAI_LIKE_API_BASE_URL || cloudflareEnv.OPENAI_LIKE_API_BASE_URL;
case 'LMStudio':
return env.LMSTUDIO_API_BASE_URL || cloudflareEnv.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
case 'Ollama':
case 'Ollama': {
let baseUrl = env.OLLAMA_API_BASE_URL || cloudflareEnv.OLLAMA_API_BASE_URL || 'http://localhost:11434';

if (env.RUNNING_IN_DOCKER === 'true') {
baseUrl = baseUrl.replace('localhost', 'host.docker.internal');
}

return baseUrl;
}
default:
return '';
}
Expand Down
28 changes: 14 additions & 14 deletions app/lib/.server/llm/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { createOpenRouter } from '@openrouter/ai-sdk-provider';
import { createMistral } from '@ai-sdk/mistral';
import { createCohere } from '@ai-sdk/cohere';

export function getAnthropicModel(apiKey: string, model: string) {
export function getAnthropicModel(apiKey: string | undefined, model: string) {
const anthropic = createAnthropic({
apiKey,
});

return anthropic(model);
}
export function getOpenAILikeModel(baseURL: string, apiKey: string, model: string) {
export function getOpenAILikeModel(baseURL: string, apiKey: string | undefined, model: string) {
const openai = createOpenAI({
baseURL,
apiKey,
Expand All @@ -27,39 +27,39 @@ export function getOpenAILikeModel(baseURL: string, apiKey: string, model: strin
return openai(model);
}

export function getCohereAIModel(apiKey: string, model: string) {
export function getCohereAIModel(apiKey: string | undefined, model: string) {
const cohere = createCohere({
apiKey,
});

return cohere(model);
}

export function getOpenAIModel(apiKey: string, model: string) {
export function getOpenAIModel(apiKey: string | undefined, model: string) {
const openai = createOpenAI({
apiKey,
});

return openai(model);
}

export function getMistralModel(apiKey: string, model: string) {
export function getMistralModel(apiKey: string | undefined, model: string) {
const mistral = createMistral({
apiKey,
});

return mistral(model);
}

export function getGoogleModel(apiKey: string, model: string) {
export function getGoogleModel(apiKey: string | undefined, model: string) {
const google = createGoogleGenerativeAI({
apiKey,
});

return google(model);
}

export function getGroqModel(apiKey: string, model: string) {
export function getGroqModel(apiKey: string | undefined, model: string) {
const openai = createOpenAI({
baseURL: 'https://api.groq.com/openai/v1',
apiKey,
Expand All @@ -68,7 +68,7 @@ export function getGroqModel(apiKey: string, model: string) {
return openai(model);
}

export function getHuggingFaceModel(apiKey: string, model: string) {
export function getHuggingFaceModel(apiKey: string | undefined, model: string) {
const openai = createOpenAI({
baseURL: 'https://api-inference.huggingface.co/v1/',
apiKey,
Expand All @@ -78,16 +78,16 @@ export function getHuggingFaceModel(apiKey: string, model: string) {
}

export function getOllamaModel(baseURL: string, model: string) {
const Ollama = ollama(model, {
const ollamaInstance = ollama(model, {
numCtx: 32768,
});

Ollama.config.baseURL = `${baseURL}/api`;
ollamaInstance.config.baseURL = `${baseURL}/api`;

return Ollama;
return ollamaInstance;
}

export function getDeepseekModel(apiKey: string, model: string) {
export function getDeepseekModel(apiKey: string | undefined, model: string) {
const openai = createOpenAI({
baseURL: 'https://api.deepseek.com/beta',
apiKey,
Expand All @@ -96,7 +96,7 @@ export function getDeepseekModel(apiKey: string, model: string) {
return openai(model);
}

export function getOpenRouterModel(apiKey: string, model: string) {
export function getOpenRouterModel(apiKey: string | undefined, model: string) {
const openRouter = createOpenRouter({
apiKey,
});
Expand All @@ -113,7 +113,7 @@ export function getLMStudioModel(baseURL: string, model: string) {
return lmstudio(model);
}

export function getXAIModel(apiKey: string, model: string) {
export function getXAIModel(apiKey: string | undefined, model: string) {
const openai = createOpenAI({
baseURL: 'https://api.x.ai/v1',
apiKey,
Expand Down
23 changes: 13 additions & 10 deletions app/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const PROVIDER_LIST: ProviderInfo[] = [
{ name: 'deepseek-coder', label: 'Deepseek-Coder', provider: 'Deepseek', maxTokenAllowed: 8000 },
{ name: 'deepseek-chat', label: 'Deepseek-Chat', provider: 'Deepseek', maxTokenAllowed: 8000 },
],
getApiKeyLink: 'https://platform.deepseek.com/api_keys',
getApiKeyLink: 'https://platform.deepseek.com/apiKeys',
},
{
name: 'Mistral',
Expand Down Expand Up @@ -242,8 +242,8 @@ const getOllamaBaseUrl = () => {

async function getOllamaModels(): Promise<ModelInfo[]> {
try {
const base_url = getOllamaBaseUrl();
const response = await fetch(`${base_url}/api/tags`);
const baseUrl = getOllamaBaseUrl();
const response = await fetch(`${baseUrl}/api/tags`);
const data = (await response.json()) as OllamaApiResponse;

return data.models.map((model: OllamaModel) => ({
Expand All @@ -253,22 +253,23 @@ async function getOllamaModels(): Promise<ModelInfo[]> {
maxTokenAllowed: 8000,
}));
} catch (e) {
console.log('No Ollama model found', e);
return [];
}
}

async function getOpenAILikeModels(): Promise<ModelInfo[]> {
try {
const base_url = import.meta.env.OPENAI_LIKE_API_BASE_URL || '';
const baseUrl = import.meta.env.OPENAI_LIKE_API_BASE_URL || '';

if (!base_url) {
if (!baseUrl) {
return [];
}

const api_key = import.meta.env.OPENAI_LIKE_API_KEY ?? '';
const response = await fetch(`${base_url}/models`, {
const apiKey = import.meta.env.OPENAI_LIKE_API_KEY ?? '';
const response = await fetch(`${baseUrl}/models`, {
headers: {
Authorization: `Bearer ${api_key}`,
Authorization: `Bearer ${apiKey}`,
},
});
const res = (await response.json()) as any;
Expand All @@ -279,6 +280,7 @@ async function getOpenAILikeModels(): Promise<ModelInfo[]> {
provider: 'OpenAILike',
}));
} catch (e) {
console.log('No OpenAI-like model found', e);
return [];
}
}
Expand Down Expand Up @@ -318,8 +320,8 @@ async function getOpenRouterModels(): Promise<ModelInfo[]> {

async function getLMStudioModels(): Promise<ModelInfo[]> {
try {
const base_url = import.meta.env.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
const response = await fetch(`${base_url}/v1/models`);
const baseUrl = import.meta.env.LMSTUDIO_API_BASE_URL || 'http://localhost:1234';
const response = await fetch(`${baseUrl}/v1/models`);
const data = (await response.json()) as any;

return data.data.map((model: any) => ({
Expand All @@ -328,6 +330,7 @@ async function getLMStudioModels(): Promise<ModelInfo[]> {
provider: 'LMStudio',
}));
} catch (e) {
console.log('No LMStudio model found', e);
return [];
}
}
Expand Down
3 changes: 3 additions & 0 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ interface Env {
OPENAI_LIKE_API_BASE_URL: string;
DEEPSEEK_API_KEY: string;
LMSTUDIO_API_BASE_URL: string;
GOOGLE_GENERATIVE_AI_API_KEY: string;
MISTRAL_API_KEY: string;
XAI_API_KEY: string;
}

0 comments on commit 4306432

Please sign in to comment.