simple model config
This commit is contained in:
@@ -62,7 +62,7 @@ function LLMResponesInfoButton({ message }: { message: ChatAssistantMessage }) {
|
||||
<LLMResponseInfoPopover
|
||||
usage={message.metadata?.usage}
|
||||
estimatedPrice={cost}
|
||||
model={message.metadata?.model?.name}
|
||||
model={message.metadata?.model?.modelId}
|
||||
/>
|
||||
</div>
|
||||
</Tooltip.Trigger>
|
||||
|
||||
@@ -279,7 +279,7 @@ const Chat = forwardRef<ChatRef, ChatProps>((props, ref) => {
|
||||
const stream = await streamResponse(
|
||||
chatModel,
|
||||
{
|
||||
model: chatModel.name,
|
||||
model: chatModel.modelId,
|
||||
messages: requestMessages,
|
||||
stream: true,
|
||||
},
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
|
||||
import { ChevronDown, ChevronUp } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
||||
import { useSettings } from '../../../contexts/SettingsContext'
|
||||
|
||||
import { GetProviderModelIds } from "../../../utils/api"
|
||||
export function ModelSelect() {
|
||||
const { settings, setSettings } = useSettings()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
||||
const activeModels = settings.activeModels.filter((model) => model.enabled)
|
||||
const[chatModelId, setChatModelId] = useState(settings.chatModelId)
|
||||
|
||||
const currProviderModels = useMemo(() => {
|
||||
return GetProviderModelIds(settings.chatModelProvider)
|
||||
}, [settings.chatModelProvider])
|
||||
|
||||
return (
|
||||
<DropdownMenu.Root open={isOpen} onOpenChange={setIsOpen}>
|
||||
@@ -17,11 +21,7 @@ export function ModelSelect() {
|
||||
{isOpen ? <ChevronUp size={12} /> : <ChevronDown size={12} />}
|
||||
</div>
|
||||
<div className="infio-chat-input-model-select__model-name">
|
||||
{
|
||||
activeModels.find(
|
||||
(option) => option.name === settings.chatModelId,
|
||||
)?.name
|
||||
}
|
||||
{chatModelId}
|
||||
</div>
|
||||
</DropdownMenu.Trigger>
|
||||
|
||||
@@ -29,18 +29,19 @@ export function ModelSelect() {
|
||||
<DropdownMenu.Content
|
||||
className="infio-popover">
|
||||
<ul>
|
||||
{activeModels.map((model) => (
|
||||
{currProviderModels.map((modelId) => (
|
||||
<DropdownMenu.Item
|
||||
key={model.name}
|
||||
key={modelId}
|
||||
onSelect={() => {
|
||||
setChatModelId(modelId)
|
||||
setSettings({
|
||||
...settings,
|
||||
chatModelId: model.name,
|
||||
chatModelId: modelId,
|
||||
})
|
||||
}}
|
||||
asChild
|
||||
>
|
||||
<li>{model.name}</li>
|
||||
<li>{modelId}</li>
|
||||
</DropdownMenu.Item>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MarkdownView, Plugin } from 'obsidian';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import { APPLY_VIEW_TYPE } from '../../constants';
|
||||
import LLMManager from '../../core/llm/manager';
|
||||
import { CustomLLMModel } from '../../types/llm/model';
|
||||
import { InfioSettings } from '../../types/settings';
|
||||
import { GetProviderModelIds } from '../../utils/api';
|
||||
import { manualApplyChangesToFile } from '../../utils/apply';
|
||||
import { removeAITags } from '../../utils/content-filter';
|
||||
import { PromptGenerator } from '../../utils/prompt-generator';
|
||||
@@ -57,31 +57,35 @@ const ControlArea: React.FC<ControlAreaProps> = ({
|
||||
selectedModel,
|
||||
onModelChange,
|
||||
isSubmitting,
|
||||
}) => (
|
||||
<div className="infio-ai-block-controls">
|
||||
<select
|
||||
className="infio-ai-block-model-select"
|
||||
value={selectedModel}
|
||||
onChange={(e) => onModelChange(e.target.value)}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{settings.activeModels
|
||||
.filter((model) => !model.isEmbeddingModel && model.enabled)
|
||||
.map((model) => (
|
||||
<option key={model.name} value={model.name}>
|
||||
{model.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button
|
||||
className="infio-ai-block-submit-button"
|
||||
onClick={onSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? "Submitting..." : "Submit"}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}) => {
|
||||
const currProviderModels = useMemo(() => {
|
||||
return GetProviderModelIds(settings.chatModelProvider)
|
||||
.map((modelId) => (
|
||||
<option key={modelId} value={modelId}>
|
||||
{modelId}
|
||||
</option>
|
||||
))
|
||||
}, [settings])
|
||||
|
||||
return (
|
||||
<div className="infio-ai-block-controls">
|
||||
<select
|
||||
className="infio-ai-block-model-select"
|
||||
value={selectedModel}
|
||||
onChange={(e) => onModelChange(e.target.value)}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{currProviderModels}
|
||||
</select>
|
||||
<button
|
||||
className="infio-ai-block-submit-button"
|
||||
onClick={onSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? "Submitting..." : "Submit"}
|
||||
</button>
|
||||
</div>);
|
||||
};
|
||||
|
||||
export const InlineEdit: React.FC<InlineEditProps> = ({
|
||||
source,
|
||||
@@ -94,14 +98,7 @@ export const InlineEdit: React.FC<InlineEditProps> = ({
|
||||
const [selectedModel, setSelectedModel] = useState(settings.chatModelId);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
const llmManager = new LLMManager({
|
||||
deepseek: settings.deepseekApiKey,
|
||||
openai: settings.openAIApiKey,
|
||||
anthropic: settings.anthropicApiKey,
|
||||
gemini: settings.geminiApiKey,
|
||||
groq: settings.groqApiKey,
|
||||
infio: settings.infioApiKey,
|
||||
});
|
||||
const llmManager = new LLMManager(settings);
|
||||
|
||||
const promptGenerator = new PromptGenerator(
|
||||
async () => {
|
||||
@@ -171,9 +168,10 @@ export const InlineEdit: React.FC<InlineEditProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
const chatModel = settings.activeModels.find(
|
||||
(model) => model.name === selectedModel
|
||||
) as CustomLLMModel;
|
||||
const chatModel = {
|
||||
provider: settings.chatModelProvider,
|
||||
modelId: settings.chatModelId,
|
||||
};
|
||||
if (!chatModel) {
|
||||
setIsSubmitting(false);
|
||||
throw new Error("Invalid chat model");
|
||||
@@ -193,7 +191,7 @@ export const InlineEdit: React.FC<InlineEditProps> = ({
|
||||
});
|
||||
|
||||
const response = await llmManager.generateResponse(chatModel, {
|
||||
model: chatModel.name,
|
||||
model: chatModel.modelId,
|
||||
messages: requestMessages,
|
||||
stream: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user