Skip to content

Commit

Permalink
Refactor getModelInstance call outside of getStreamTextArguments so w…
Browse files Browse the repository at this point in the history
…e don't need an API key for the selected model if we're using claude
  • Loading branch information
bhackett1024 committed Jan 16, 2025
1 parent f040c9b commit e014056
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions app/lib/.server/llm/stream-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ export async function getStreamTextArguments(props: {

const dynamicMaxTokens = modelDetails && modelDetails.maxTokenAllowed ? modelDetails.maxTokenAllowed : MAX_TOKENS;

const provider = PROVIDER_LIST.find((p) => p.name === currentProvider) || DEFAULT_PROVIDER;

let systemPrompt =
PromptLibrary.getPropmtFromLibrary(promptId || 'default', {
cwd: WORK_DIR,
Expand All @@ -202,12 +200,8 @@ export async function getStreamTextArguments(props: {
const coreMessages = convertToCoreMessages(processedMessages as any);

return {
model: provider.getModelInstance({
model: currentModel,
serverEnv,
apiKeys,
providerSettings,
}),
currentModel,
currentProvider,
system: systemPrompt,
maxTokens: dynamicMaxTokens,
messages: coreMessages,
Expand All @@ -224,5 +218,16 @@ export async function streamText(props: {
promptId?: string;
}) {
const args = await getStreamTextArguments(props);
return _streamText({ ...args, ...props.options });
const { currentModel, currentProvider } = args;

const provider = PROVIDER_LIST.find((p) => p.name === currentProvider) || DEFAULT_PROVIDER;

const model = provider.getModelInstance({
model: currentModel,
serverEnv: props.env,
apiKeys: props.apiKeys,
providerSettings: props.providerSettings,
});

return _streamText({ ...args, ...props.options, model });
}

0 comments on commit e014056

Please sign in to comment.