ReviewOS

also looking at this

stacks/stx

chore: wip stx improvements

#1649
Merged fingersandmind wants to merge feat/stx-improvements into main
241 files +19022 -1323
packages/ai/src/chat.tsadded+28-0
Changes to packages/ai/src/chat.ts
@@ -0,0 +1,28 @@
1import type { ChatOptions, ChatResponse, Message } from './types'
2import { useAI } from './ai'
3
4export async function chat(
5 messages: Message[],
6 options?: ChatOptions & { provider?: string },
7): Promise<ChatResponse> {
8 const { provider: providerName, ...chatOptions } = options ?? {}
9 const provider = useAI(providerName)
10 return provider.chat(messages, chatOptions)
11}
12
13export async function ask(
14 prompt: string,
15 options?: ChatOptions & { provider?: string; system?: string },
16): Promise<string> {
17 const { system, ...rest } = options ?? {}
18 const messages: Message[] = []
19
20 if (system) {
21 messages.push({ role: 'system', content: system })
22 }
23
24 messages.push({ role: 'user', content: prompt })
25
26 const response = await chat(messages, rest)
27 return response.content
28}