Skip to content

Commit 19c41a9

Browse files
committed
Fetch model and chat node fixes
1 parent d0c2fb0 commit 19c41a9

File tree

9 files changed

+47
-31
lines changed

9 files changed

+47
-31
lines changed

client/src/App.tsx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,43 @@ import { useEffect } from "react";
44
import { useStore } from "@/lib/store";
55
import { defaultLocalModels, modelService } from "./lib/localmodels";
66
import { PRESET_ENDPOINTS } from "./lib/constants";
7-
import { CustomModel } from "./lib/types";
7+
import { CustomModel, GlobalSettings } from "./lib/types";
88

99
function App() {
10-
const { settings, setSettings } = useStore();
10+
const { settings, updateCustomModels } = useStore();
1111

1212
useEffect(() => {
1313
const fetchModels = async () => {
1414
console.log('fetching models');
15-
// Get all endpoints from settings
1615
const endpoints = PRESET_ENDPOINTS.map(e => ({
1716
url: e.url,
1817
provider: 'openai'
1918
}));
20-
21-
// Fetch models from all configured endpoints
19+
2220
const modelPromises = endpoints.map(e =>
2321
modelService.getAvailableModels(e.url)
2422
);
25-
23+
2624
try {
2725
const modelLists = await Promise.allSettled(modelPromises);
2826
const allModels = modelLists
2927
.filter((result): result is PromiseFulfilledResult<CustomModel[]> =>
3028
result.status === 'fulfilled'
3129
)
3230
.flatMap(result => result.value);
33-
34-
// Merge with defaults, removing duplicates
31+
3532
const existingIds = new Set(defaultLocalModels.map(m => m.id));
3633
const newModels = allModels.filter(m => !existingIds.has(m.id));
37-
38-
setSettings({
39-
...settings,
40-
customModels: [
41-
...settings.customModels.filter(m =>
42-
!endpoints.some(e => m.endpoint === e.url)
43-
),
44-
...defaultLocalModels,
45-
...newModels
46-
]
47-
});
34+
35+
const updatedModels = [
36+
...settings.customModels.filter(m =>
37+
!endpoints.some(e => m.endpoint === e.url)
38+
),
39+
...defaultLocalModels,
40+
...newModels
41+
];
42+
43+
updateCustomModels(updatedModels);
4844
} catch (error) {
4945
// console.error('Error fetching models:', error);
5046
}
@@ -53,7 +49,7 @@ function App() {
5349
fetchModels();
5450
const interval = setInterval(fetchModels, 120000); // 2 minutes
5551
return () => clearInterval(interval);
56-
}, []);
52+
}, [updateCustomModels]);
5753

5854
useEffect(() => {
5955
document.documentElement.style.setProperty('--primary-color', settings.primaryColor);

client/src/components/ChatNode.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
SelectValue,
2121
} from "@/components/ui/select";
2222
import { AIModel, APIResponseMetrics, CustomModel, Message, availableModels } from "@/lib/types";
23-
import { cn } from "@/lib/utils";
23+
import { cn, sanitizeChatMessages } from "@/lib/utils";
2424
import { useStore } from "@/lib/store";
2525
import { Copy, Check } from "lucide-react";
2626
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
@@ -278,10 +278,11 @@ export function ChatNode({ id, data: initialData }: NodeProps) {
278278
const response = await anthropic.messages.create({
279279
model: model,
280280
system: enhancedSystemPrompt,
281-
messages: allMessages.map(msg => ({
281+
messages:
282+
sanitizeChatMessages(allMessages.map(msg => ({
282283
role: msg.role === "user" ? "user" : "assistant",
283284
content: msg.content
284-
})),
285+
}))),
285286
max_tokens: 8192,
286287
...filterAnthropicAISettings(settings),
287288
});
@@ -324,11 +325,11 @@ export function ChatNode({ id, data: initialData }: NodeProps) {
324325
},
325326
body: JSON.stringify({
326327
model,
327-
messages: [
328+
messages: sanitizeChatMessages([
328329
{ role: 'system', content: enhancedSystemPrompt },
329330
...allMessages.slice(0, -1),
330331
{ role: "user", content: messageContent }
331-
].filter(m => m.content),
332+
]).filter(m => m.content),
332333
// we shouldnt pass any of these unless they are changed from the defaults
333334
...filterAISettings(settings),
334335
}),

client/src/components/SettingsDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function SettingsDialog({ open, onOpenChange }: SettingsDialogProps) {
7878

7979
<div className="flex justify-center">
8080
<img src={logo} alt="Curiso.ai" title="Curiso.ai" className="w-12 h-12" /></div>
81-
<div className="flex justify-center"><p className="text-sm text-muted-foreground justify-center mb-2">Version v1.1.0 by Carsen Klock</p></div>
81+
<div className="flex justify-center"><p className="text-sm text-muted-foreground justify-center mb-2">Version v1.1.1 by Carsen Klock</p></div>
8282
<strong>Curiso.ai</strong> is an infinite canvas for your thoughts—a platform that seamlessly connects nodes and AI services so you can explore ideas in depth without repeating yourself. By guiding the direction of each conversation, Curiso.ai empowers advanced users to unlock richer, more accurate AI interactions.
8383
</div>
8484
<div className="space-y-2 mt-2">

client/src/lib/store.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand';
22
import { persist, type StorageValue } from 'zustand/middleware';
3-
import type { GlobalSettings } from './types';
3+
import type { CustomModel, GlobalSettings } from './types';
44
import { SecureStorage, StorageKey } from './secureStorage';
55
import { nanoid } from 'nanoid';
66
import { themeColors } from './constants';
@@ -129,13 +129,20 @@ interface StoreState {
129129
settings: GlobalSettings;
130130
setSettings: (settings: GlobalSettings) => void;
131131
clearAllData: () => Promise<void>;
132+
updateCustomModels: (models: CustomModel[]) => void;
132133
}
133134

134135
export const useStore = create<StoreState>()(
135136
persist(
136137
(set) => ({
137138
settings: defaultSettings,
138139
setSettings: (settings) => set({ settings }),
140+
updateCustomModels: (models) => set((state) => ({
141+
settings: {
142+
...state.settings,
143+
customModels: models
144+
}
145+
})),
139146
clearAllData: async () => {
140147
const storage = await getSecureStorage();
141148
storage.clear();

client/src/lib/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@ import { twMerge } from "tailwind-merge"
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs))
66
}
7+
8+
export function sanitizeChatMessage(message: any) {
9+
return {
10+
role: message.role,
11+
content: message.content,
12+
...(message.name ? { name: message.name } : {})
13+
};
14+
}
15+
16+
export function sanitizeChatMessages(messages: any[]) {
17+
return messages.map(sanitizeChatMessage);
18+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "curiso.ai",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"author": "Carsen Klock",
55
"type": "module",
66
"license": "MIT",

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "curiso-ai"
3-
version = "1.1.0"
3+
version = "1.1.1"
44
description = "Curiso AI Desktop"
55
authors = ["Carsen Klock"]
66
license = "MIT"

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"identifier": "com.curiso.ai",
33
"productName": "Curiso AI",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"build": {
66
"beforeBuildCommand": "npm run build",
77
"beforeDevCommand": "npm run dev",

0 commit comments

Comments
 (0)