Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bnleft committed Nov 21, 2024
1 parent e7b497c commit 6bab008
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/components/chat/input.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion app/components/chat/select.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion app/components/chat/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function Settings() {
: "opacity-100 cursor-text",
)}
disabled={!!initialKey}
autoComplete={'off'}
autoComplete={"off"}
/>
<div
className={cn(
Expand Down
9 changes: 7 additions & 2 deletions app/lib/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {Message, Model, Provider, ProviderMetadata} from '@/lib/types';
import {
type Message,
type Model,
Provider,
type ProviderMetadata,
} from "@/lib/types";

// TODO: add more
export const models: Model[] = [
Expand Down Expand Up @@ -36,7 +41,7 @@ const ProviderInfo: Record<Provider, ProviderMetadata> = {
},
[Provider.XAI]: {
domain: "x.ai",
}
},
};

export const defaultModel = models[0];
Expand Down
4 changes: 2 additions & 2 deletions app/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export enum Provider {

export type ProviderMetadata = {
domain: string;
}
};

type Company = {
name: string;
domain: string;
}
};

export type Model = {
id: string;
Expand Down
52 changes: 30 additions & 22 deletions app/routes/api.llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -47,45 +47,49 @@ export async function action({ request }: ActionFunctionArgs) {

type ProviderConfig = {
endpoint: string;
method: 'GET' | 'POST';
method: "GET" | "POST";
headers: Record<string, string>;
body?: string;
}
};

async function validateApiKey(provider: Provider, key: string, model: string): Promise<boolean> {
async function validateApiKey(
provider: Provider,
key: string,
model: string,
): Promise<boolean> {
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];
Expand All @@ -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;
Expand All @@ -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}`);
}
Expand Down

0 comments on commit 6bab008

Please sign in to comment.