From 6bab00852c99d31683f08aa632de060b5cf5f14d Mon Sep 17 00:00:00 2001 From: Bryant Le Date: Thu, 21 Nov 2024 02:27:44 -0600 Subject: [PATCH] chore: lint --- app/components/chat/input.tsx | 2 +- app/components/chat/select.tsx | 2 +- app/components/chat/settings.tsx | 2 +- app/lib/data.ts | 9 ++++-- app/lib/types.ts | 4 +-- app/routes/api.llm.ts | 52 ++++++++++++++++++-------------- 6 files changed, 42 insertions(+), 29 deletions(-) diff --git a/app/components/chat/input.tsx b/app/components/chat/input.tsx index f24da3c..7deaadf 100644 --- a/app/components/chat/input.tsx +++ b/app/components/chat/input.tsx @@ -1,6 +1,6 @@ import { defaultMessages } from "@/lib/data"; import { useLLMStore, useMessageStore } from "@/lib/stores"; -import type {APIError, Message} from '@/lib/types'; +import type { APIError, Message } from "@/lib/types"; import { cn, randomKey } from "@/lib/utils"; import { useChat } from "ai/react"; import type React from "react"; diff --git a/app/components/chat/select.tsx b/app/components/chat/select.tsx index d8773aa..52c71f7 100644 --- a/app/components/chat/select.tsx +++ b/app/components/chat/select.tsx @@ -1,4 +1,4 @@ -import { models, ProviderLogo } from '@/lib/data'; +import { ProviderLogo, models } from "@/lib/data"; import { useLLMStore } from "@/lib/stores"; import type { Model } from "@/lib/types"; import { cn } from "@/lib/utils"; diff --git a/app/components/chat/settings.tsx b/app/components/chat/settings.tsx index 0714c81..c9635b3 100644 --- a/app/components/chat/settings.tsx +++ b/app/components/chat/settings.tsx @@ -61,7 +61,7 @@ export default function Settings() { : "opacity-100 cursor-text", )} disabled={!!initialKey} - autoComplete={'off'} + autoComplete={"off"} />
= { }, [Provider.XAI]: { domain: "x.ai", - } + }, }; export const defaultModel = models[0]; diff --git a/app/lib/types.ts b/app/lib/types.ts index e1270fe..9f81f21 100644 --- a/app/lib/types.ts +++ b/app/lib/types.ts @@ -8,12 +8,12 @@ export enum Provider { export type ProviderMetadata = { domain: string; -} +}; type Company = { name: string; domain: string; -} +}; export type Model = { id: string; diff --git a/app/routes/api.llm.ts b/app/routes/api.llm.ts index ea0c849..f163c75 100644 --- a/app/routes/api.llm.ts +++ b/app/routes/api.llm.ts @@ -2,8 +2,8 @@ import { Provider } from "@/lib/types"; import { createAnthropic } from "@ai-sdk/anthropic"; import { createOpenAI } from "@ai-sdk/openai"; import { createXai } from "@ai-sdk/xai"; -import { ActionFunctionArgs } from '@remix-run/node'; -import { streamText } from 'ai'; +import type { ActionFunctionArgs } from "@remix-run/node"; +import { streamText } from "ai"; import { z } from "zod"; const StreamChatSchema = z.object({ @@ -47,45 +47,49 @@ export async function action({ request }: ActionFunctionArgs) { type ProviderConfig = { endpoint: string; - method: 'GET' | 'POST'; + method: "GET" | "POST"; headers: Record; body?: string; -} +}; -async function validateApiKey(provider: Provider, key: string, model: string): Promise { +async function validateApiKey( + provider: Provider, + key: string, + model: string, +): Promise { if (!key) return false; const configs: { [key in Provider]: ProviderConfig } = { [Provider.ANTHROPIC]: { - endpoint: 'https://api.anthropic.com/v1/messages', - method: 'POST', + endpoint: "https://api.anthropic.com/v1/messages", + method: "POST", headers: { - 'x-api-key': key, + "x-api-key": key, "anthropic-version": "2023-06-01", - 'content-type': 'application/json' + "content-type": "application/json", }, body: JSON.stringify({ model: model, max_tokens: 1, - messages: [{ role: 'user', content: 'test' }] - }) + messages: [{ role: "user", content: "test" }], + }), }, [Provider.XAI]: { endpoint: `https://api.x.ai/v1/models/${model}`, - method: 'GET', + method: "GET", headers: { - 'Authorization': `Bearer ${key}`, - 'Content-Type': 'application/json' - } + Authorization: `Bearer ${key}`, + "Content-Type": "application/json", + }, }, [Provider.OPENAI]: { endpoint: `https://api.openai.com/v1/models/${model}`, - method: 'GET', + method: "GET", headers: { - 'Authorization': `Bearer ${key}`, - 'Content-Type': 'application/json' - } - } + Authorization: `Bearer ${key}`, + "Content-Type": "application/json", + }, + }, }; const config = configs[provider]; @@ -95,7 +99,7 @@ async function validateApiKey(provider: Provider, key: string, model: string): P const response = await fetch(config.endpoint, { method: config.method, headers: config.headers, - ...(config.body && { body: config.body }) + ...(config.body && { body: config.body }), }); return response.ok; @@ -105,7 +109,11 @@ async function validateApiKey(provider: Provider, key: string, model: string): P } } -async function createLLMClient(provider: Provider, model: string, key: string | undefined) { +async function createLLMClient( + provider: Provider, + model: string, + key: string | undefined, +) { if (!key) { throw new Error(`Must populate an API key for ${provider}`); }