Skip to content

Commit 42da0fd

Browse files
authored
merging master into development (#61)
merging master into development to bring development up-to-speed with master
1 parent 3551ff4 commit 42da0fd

3 files changed

Lines changed: 138 additions & 1 deletion

File tree

src/client/app/personality-test/page.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AnimatedLogo from "@components/AnimatedLogo" // Component for displaying
99
import ShiningButton from "@components/ShiningButton" // Custom button component with a shining effect
1010
import AnimatedBeam from "@components/AnimatedBeam" // Component for animated beam effect
1111
import ShinyCard from "@components/ShinyCard" // Custom card component with a shiny effect
12+
import ModelSelection from "@components/ModelSelection"
1213
import toast from "react-hot-toast" // Library for displaying toast notifications
1314

1415
/**
@@ -169,6 +170,7 @@ const PersonalityTest = () => {
169170
const [isReferred, setIsReferred] = useState(null) // isReferred: boolean | null
170171
// State to store the referral code entered by the user.
171172
const [referralCode, setReferralCode] = useState("") // referralCode: string
173+
const [showModelSelection, setShowModelSelection] = useState(false)
172174

173175
/**
174176
* useEffect hook to fetch existing personality data on component mount.
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import React, { useState, useEffect } from "react"
2+
import ShiningButton from "@components/ShiningButton"
3+
import ModalDialog from "@components/ModalDialog" // Assume this is available
4+
import toast from "react-hot-toast"
5+
6+
const ModelSelection = ({ onProceed }) => {
7+
const [availableModels, setAvailableModels] = useState([])
8+
const [selectedModel, setSelectedModel] = useState("")
9+
const [apiKeyDialog, setApiKeyDialog] = useState(false)
10+
const [apiKey, setApiKey] = useState("")
11+
const [selectedProvider, setSelectedProvider] = useState("")
12+
13+
const cloudModels = [
14+
{ name: "OpenAI", value: "openai" },
15+
{ name: "Gemini", value: "gemini" },
16+
{ name: "Claude", value: "claude" }
17+
]
18+
19+
useEffect(() => {
20+
const fetchModels = async () => {
21+
try {
22+
const models = await window.electron.invoke("get-ollama-models")
23+
setAvailableModels(models)
24+
// Set a default model: first local model or first cloud model
25+
if (models.length > 0) {
26+
setSelectedModel(models[0])
27+
await saveModel(models[0])
28+
} else {
29+
setSelectedModel(cloudModels[0].value)
30+
await handleCloudModelSelection(cloudModels[0].value)
31+
}
32+
} catch (error) {
33+
toast.error("Error fetching available models.")
34+
}
35+
}
36+
fetchModels()
37+
}, [])
38+
39+
const saveModel = async (model) => {
40+
try {
41+
await window.electron.invoke("set-db-data", {
42+
data: { selectedModel: model }
43+
})
44+
} catch (error) {
45+
toast.error("Error saving model selection.")
46+
}
47+
}
48+
49+
const handleModelChange = async (model) => {
50+
setSelectedModel(model)
51+
if (cloudModels.some((m) => m.value === model)) {
52+
await handleCloudModelSelection(model)
53+
} else {
54+
await saveModel(model)
55+
}
56+
}
57+
58+
const handleCloudModelSelection = async (model) => {
59+
setSelectedProvider(model)
60+
const hasKey = await window.electron.invoke("check-api-key", model)
61+
if (!hasKey) {
62+
setApiKeyDialog(true)
63+
} else {
64+
await saveModel(model)
65+
}
66+
}
67+
68+
const handleApiKeySubmit = async () => {
69+
try {
70+
await window.electron.invoke("set-api-key", {
71+
provider: selectedProvider,
72+
apiKey
73+
})
74+
await saveModel(selectedProvider)
75+
setApiKeyDialog(false)
76+
setApiKey("")
77+
toast.success("API key saved and model selected.")
78+
} catch (error) {
79+
toast.error("Error saving API key.")
80+
}
81+
}
82+
83+
return (
84+
<div className="w-4/5 max-w-lg font-Poppins bg-matteblack p-10 rounded-2xl shadow-2xl text-white">
85+
<h2 className="text-3xl font-bold mb-6 text-center">
86+
Select AI Model
87+
</h2>
88+
<p className="text-gray-300 mb-4 text-center">
89+
Choose a model to power your knowledge graph.
90+
</p>
91+
<select
92+
value={selectedModel}
93+
onChange={(e) => handleModelChange(e.target.value)}
94+
className="bg-transparent border-2 border-gray-400 text-white p-2 rounded-xl pr-4 w-full mb-4"
95+
>
96+
{cloudModels.map((model) => (
97+
<option
98+
className="bg-matteblack"
99+
key={model.value}
100+
value={model.value}
101+
>
102+
{model.name} (Cloud)
103+
</option>
104+
))}
105+
{availableModels.map((model) => (
106+
<option className="bg-matteblack" key={model} value={model}>
107+
{model} (Local)
108+
</option>
109+
))}
110+
{availableModels.length === 0 && (
111+
<option className="bg-matteblack" value="" disabled>
112+
No local models available.
113+
</option>
114+
)}
115+
</select>
116+
{apiKeyDialog && (
117+
<ModalDialog
118+
title={`Enter API Key for ${selectedProvider}`}
119+
description="Please enter your API key to use this model."
120+
onCancel={() => setApiKeyDialog(false)}
121+
onConfirm={handleApiKeySubmit}
122+
confirmButtonText="Save"
123+
showInput={true}
124+
inputValue={apiKey}
125+
onInputChange={setApiKey}
126+
/>
127+
)}
128+
<ShiningButton onClick={onProceed} className="w-full mt-4">
129+
Continue
130+
</ShiningButton>
131+
</div>
132+
)
133+
}
134+
135+
export default ModelSelection

src/server/agents/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async def create_message(to: str, subject: str, message: str) -> str:
148148
print(type(elaborated_message))
149149

150150
msg = MIMEText(
151-
elaborated_message
151+
elaborated_message["email"]["body"]
152152
+ "\n\nThis email was sent via Sentient, a personal AI companion with agentic integrations and graph memory.\n\nLearn more at https://existence.technology/sentient\n\n Emails are generated by AI models and may not always be accurate or contextually relevant."
153153
)
154154
msg.add_header("To", to)

0 commit comments

Comments
 (0)