diff --git a/src/hooks/useMessageOption.tsx b/src/hooks/useMessageOption.tsx
index f22d27b..745b0fe 100644
--- a/src/hooks/useMessageOption.tsx
+++ b/src/hooks/useMessageOption.tsx
@@ -12,6 +12,7 @@ import {
import { useStoreMessageOption } from "~store/option"
import { saveHistory, saveMessage } from "~libs/db"
import { useNavigate } from "react-router-dom"
+import { notification } from "antd"
export type BotResponse = {
bot: {
@@ -253,22 +254,58 @@ export const useMessageOption = () => {
setIsProcessing(false)
} catch (e) {
+ console.log(e)
+
+ if (e?.name === "AbortError") {
+ newMessage[appendingIndex].message = newMessage[
+ appendingIndex
+ ].message.slice(0, -1)
+
+ setHistory([
+ ...history,
+ {
+ role: "user",
+ content: message,
+ image
+ },
+ {
+ role: "assistant",
+ content: newMessage[appendingIndex].message
+ }
+ ])
+
+ if (historyId) {
+ await saveMessage(historyId, selectedModel, "user", message, [image])
+ await saveMessage(
+ historyId,
+ selectedModel,
+ "assistant",
+ newMessage[appendingIndex].message,
+ []
+ )
+ } else {
+ const newHistoryId = await saveHistory(message)
+ await saveMessage(newHistoryId.id, selectedModel, "user", message, [
+ image
+ ])
+ await saveMessage(
+ newHistoryId.id,
+ selectedModel,
+ "assistant",
+ newMessage[appendingIndex].message,
+ []
+ )
+ setHistoryId(newHistoryId.id)
+ }
+ } else {
+ notification.error({
+ message: "Error",
+ description: e?.message || "Something went wrong"
+ })
+ }
+
setIsProcessing(false)
setStreaming(false)
-
- setMessages([
- ...messages,
- {
- isBot: true,
- name: selectedModel,
- message: `Something went wrong. Check out the following logs:
- \`\`\`
- ${e?.message}
- \`\`\`
- `,
- sources: []
- }
- ])
}
}
diff --git a/src/libs/byte-formater.ts b/src/libs/byte-formater.ts
new file mode 100644
index 0000000..3499487
--- /dev/null
+++ b/src/libs/byte-formater.ts
@@ -0,0 +1,23 @@
+const UNITS = [
+ "byte",
+ "kilobyte",
+ "megabyte",
+ "gigabyte",
+ "terabyte",
+ "petabyte"
+]
+
+const getValueAndUnit = (n: number) => {
+ const i = n == 0 ? 0 : Math.floor(Math.log(n) / Math.log(1024))
+ const value = n / Math.pow(1024, i)
+ return { value, unit: UNITS[i] }
+}
+
+export const bytePerSecondFormatter = (n: number) => {
+ const { unit, value } = getValueAndUnit(n)
+ return new Intl.NumberFormat("en", {
+ notation: "compact",
+ style: "unit",
+ unit
+ }).format(value)
+}
diff --git a/src/routes/option-model.tsx b/src/routes/option-model.tsx
index 1cbbf87..3f5a020 100644
--- a/src/routes/option-model.tsx
+++ b/src/routes/option-model.tsx
@@ -1,9 +1,10 @@
import OptionLayout from "~components/Option/Layout"
+import { ModelsBody } from "~components/Option/Models"
export const OptionModal = () => {
return (
- yo
+
)
}
diff --git a/src/services/ollama.ts b/src/services/ollama.ts
index 5ca0fcd..fb256ed 100644
--- a/src/services/ollama.ts
+++ b/src/services/ollama.ts
@@ -53,6 +53,47 @@ export const isOllamaRunning = async () => {
}
}
+export const getAllModels = async () => {
+ const baseUrl = await getOllamaURL()
+ const response = await fetch(`${cleanUrl(baseUrl)}/api/tags`)
+ if (!response.ok) {
+ throw new Error(response.statusText)
+ }
+ const json = await response.json()
+
+ return json.models as {
+ name: string
+ model: string
+ modified_at: string
+ size: number
+ digest: string
+ details: {
+ parent_model: string
+ format: string
+ family: string
+ families: string[]
+ parameter_size: string
+ quantization_level: string
+ }
+ }[]
+}
+
+export const deleteModel= async (model: string) => {
+ const baseUrl = await getOllamaURL()
+ const response = await fetch(`${cleanUrl(baseUrl)}/api/delete`, {
+ method: "DELETE",
+ headers: {
+ "Content-Type": "application/json"
+ },
+ body: JSON.stringify({ name: model })
+ })
+
+ if (!response.ok) {
+ throw new Error(response.statusText)
+ }
+ return response.json()
+}
+
export const fetchModels = async () => {
try {
const baseUrl = await getOllamaURL()
@@ -65,6 +106,17 @@ export const fetchModels = async () => {
return json.models as {
name: string
model: string
+ modified_at: string
+ size: number
+ digest: string
+ details: {
+ parent_model: string
+ format: string
+ family: string
+ families: string[]
+ parameter_size: string
+ quantization_level: string
+ }
}[]
} catch (e) {
console.error(e)