-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #275
- Loading branch information
Showing
67 changed files
with
1,316 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const runtime = 'edge'; | ||
export { openaiStreamingRelayHandler as POST } from '~/modules/llms/transports/server/openai/openai.streaming'; | ||
export { llmStreamingRelayHandler as POST } from '~/modules/llms/server/llm.server.streaming'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { DLLMId } from './store-llms'; | ||
import type { OpenAIWire } from './server/openai/openai.wiretypes'; | ||
import { findVendorForLlmOrThrow } from './vendors/vendors.registry'; | ||
|
||
|
||
// LLM Client Types | ||
// NOTE: Model List types in '../server/llm.server.types'; | ||
|
||
export interface VChatMessageIn { | ||
role: 'assistant' | 'system' | 'user'; // | 'function'; | ||
content: string; | ||
//name?: string; // when role: 'function' | ||
} | ||
|
||
export type VChatFunctionIn = OpenAIWire.ChatCompletion.RequestFunctionDef; | ||
|
||
export interface VChatMessageOut { | ||
role: 'assistant' | 'system' | 'user'; | ||
content: string; | ||
finish_reason: 'stop' | 'length' | null; | ||
} | ||
|
||
export interface VChatMessageOrFunctionCallOut extends VChatMessageOut { | ||
function_name: string; | ||
function_arguments: object | null; | ||
} | ||
|
||
|
||
// LLM Client Functions | ||
|
||
export async function llmChatGenerateOrThrow<TSourceSetup = unknown, TAccess = unknown, TLLMOptions = unknown>( | ||
llmId: DLLMId, | ||
messages: VChatMessageIn[], | ||
functions: VChatFunctionIn[] | null, forceFunctionName: string | null, | ||
maxTokens?: number, | ||
): Promise<VChatMessageOut | VChatMessageOrFunctionCallOut> { | ||
|
||
// id to DLLM and vendor | ||
const { llm, vendor } = findVendorForLlmOrThrow<TSourceSetup, TAccess, TLLMOptions>(llmId); | ||
|
||
// FIXME: relax the forced cast | ||
const options = llm.options as TLLMOptions; | ||
|
||
// get the access | ||
const partialSourceSetup = llm._source.setup; | ||
const access = vendor.getTransportAccess(partialSourceSetup); | ||
|
||
// execute via the vendor | ||
return await vendor.rpcChatGenerateOrThrow(access, options, messages, functions, forceFunctionName, maxTokens); | ||
} | ||
|
||
|
||
export async function llmStreamingChatGenerate<TSourceSetup = unknown, TAccess = unknown, TLLMOptions = unknown>( | ||
llmId: DLLMId, | ||
messages: VChatMessageIn[], | ||
functions: VChatFunctionIn[] | null, | ||
forceFunctionName: string | null, | ||
abortSignal: AbortSignal, | ||
onUpdate: (update: Partial<{ text: string, typing: boolean, originLLM: string }>, done: boolean) => void, | ||
): Promise<void> { | ||
|
||
// id to DLLM and vendor | ||
const { llm, vendor } = findVendorForLlmOrThrow<TSourceSetup, TAccess, TLLMOptions>(llmId); | ||
|
||
// FIXME: relax the forced cast | ||
const llmOptions = llm.options as TLLMOptions; | ||
|
||
// get the access | ||
const partialSourceSetup = llm._source.setup; | ||
const access = vendor.getTransportAccess(partialSourceSetup); // as ChatStreamInputSchema['access']; | ||
|
||
// execute via the vendor | ||
return await vendor.streamingChatGenerateOrThrow(access, llmId, llmOptions, messages, functions, forceFunctionName, abortSignal, onUpdate); | ||
} |
Oops, something went wrong.