also looking at this
chore: wip stx improvements
#1649
241 files
+19022
-1323
| @@ -0,0 +1,28 @@ | ||
| 1 | import type { ChatOptions, ChatResponse, Message } from './types' | |
| 2 | import { useAI } from './ai' | |
| 3 | ||
| 4 | export 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 | ||
| 13 | export 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 | } | |