forked from React-Group/interstellar_ai
Merge branch 'main' of interstellardevelopment.org:sageTheDm/interstellar_ai
This commit is contained in:
commit
a9267b6cd6
2 changed files with 21 additions and 22 deletions
|
@ -12,9 +12,11 @@ import PrivacySettings from './PrivacySettings';
|
||||||
import FontSizeSetting from './FontSize';
|
import FontSizeSetting from './FontSize';
|
||||||
import OpenSourceModeToggle from './OpenSourceToggle';
|
import OpenSourceModeToggle from './OpenSourceToggle';
|
||||||
import {
|
import {
|
||||||
|
changeHistory,
|
||||||
changeSettings,
|
changeSettings,
|
||||||
createAccount,
|
createAccount,
|
||||||
deleteAccount,
|
deleteAccount,
|
||||||
|
getHistory,
|
||||||
} from '../../backend/database';
|
} from '../../backend/database';
|
||||||
import ThemeDropdown from './DropDownTheme';
|
import ThemeDropdown from './DropDownTheme';
|
||||||
|
|
||||||
|
@ -372,7 +374,11 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
localStorage.setItem("currentEmail", useEmail)
|
localStorage.setItem("currentEmail", useEmail)
|
||||||
alert('Account successfully changed!')
|
alert('Account successfully changed!')
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
|
} else {
|
||||||
|
alert("failed to send settings")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
alert("failed to create account")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -409,7 +415,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
checked={myBoolean}
|
checked={myBoolean}
|
||||||
setChecked={setMyBoolean}
|
setChecked={setMyBoolean}
|
||||||
/>
|
/>
|
||||||
<TextSettings
|
<TextSettings
|
||||||
label="Nearest City"
|
label="Nearest City"
|
||||||
value={weatherInfo}
|
value={weatherInfo}
|
||||||
type='text'
|
type='text'
|
||||||
|
@ -624,6 +630,7 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = (
|
||||||
onClick={handleLogout} // Function to call on click
|
onClick={handleLogout} // Function to call on click
|
||||||
className="update-credentials-button" // Custom styling class
|
className="update-credentials-button" // Custom styling class
|
||||||
/>
|
/>
|
||||||
|
<p>WARNING: Will delete your chat history.</p>
|
||||||
<ButtonSetting
|
<ButtonSetting
|
||||||
label="Update Credentials" // Button label
|
label="Update Credentials" // Button label
|
||||||
onClick={handleUpdateCredentials} // Function to call on click
|
onClick={handleUpdateCredentials} // Function to call on click
|
||||||
|
|
34
py/ai.py
34
py/ai.py
|
@ -20,34 +20,29 @@ class AI:
|
||||||
|
|
||||||
for chunk in stream:
|
for chunk in stream:
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
return_class.ai_response[access_token] += chunk['message']['content']
|
return_class.ai_response[access_token] += chunk["message"]["content"]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_mistralai(model, messages, return_class, access_token, api_key):
|
def process_mistralai(model, messages, return_class, access_token, api_key):
|
||||||
|
|
||||||
client = Mistral(api_key=api_key)
|
client = Mistral(api_key=api_key)
|
||||||
|
|
||||||
stream_response = client.chat.stream(
|
stream_response = client.chat.stream(model=model, messages=messages)
|
||||||
model=model,
|
|
||||||
messages=messages
|
|
||||||
)
|
|
||||||
|
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
return_class.ai_response[access_token] = ""
|
return_class.ai_response[access_token] = ""
|
||||||
|
|
||||||
for chunk in stream_response:
|
for chunk in stream_response:
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
return_class.ai_response[access_token] += chunk.data.choices[0].delta.content
|
return_class.ai_response[access_token] += chunk.data.choices[
|
||||||
|
0
|
||||||
|
].delta.content
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_openai(model, messages, return_class, access_token, api_key):
|
def process_openai(model, messages, return_class, access_token, api_key):
|
||||||
|
|
||||||
client = OpenAI(api_key=api_key)
|
client = OpenAI(api_key=api_key)
|
||||||
|
|
||||||
stream_response = client.chat.completions.create(
|
stream_response = client.chat.completions.create(
|
||||||
model=model,
|
model=model, messages=messages, stream=True
|
||||||
messages=messages,
|
|
||||||
stream=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
|
@ -59,16 +54,15 @@ class AI:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_anthropic(model, messages, return_class, access_token, api_key):
|
def process_anthropic(model, messages, return_class, access_token, api_key):
|
||||||
|
|
||||||
client = anthropic.Anthropic(api_key=api_key)
|
client = anthropic.Anthropic(api_key=api_key)
|
||||||
|
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
return_class.ai_response[access_token] = ""
|
return_class.ai_response[access_token] = ""
|
||||||
|
|
||||||
with client.messages.stream(
|
with client.messages.stream(
|
||||||
max_tokens=1024,
|
max_tokens=1024,
|
||||||
model=model,
|
model=model,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
) as stream:
|
) as stream:
|
||||||
for text in stream.text_stream:
|
for text in stream.text_stream:
|
||||||
with return_class.ai_response_lock:
|
with return_class.ai_response_lock:
|
||||||
|
@ -76,16 +70,15 @@ class AI:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_google(model, messages, return_class, access_token, api_key):
|
def process_google(model, messages, return_class, access_token, api_key):
|
||||||
|
message = messages[-1]["content"]
|
||||||
message = messages[-1]['content']
|
|
||||||
messages.pop()
|
messages.pop()
|
||||||
|
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
msg['parts'] = msg.pop('content')
|
msg["parts"] = msg.pop()["content"]
|
||||||
|
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
if msg['role'] == 'assistant':
|
if msg["role"] == "assistant":
|
||||||
msg['role'] = 'model'
|
msg["role"] = "model"
|
||||||
|
|
||||||
genai.configure(api_key=api_key)
|
genai.configure(api_key=api_key)
|
||||||
|
|
||||||
|
@ -93,7 +86,6 @@ class AI:
|
||||||
|
|
||||||
chat = model.start_chat(
|
chat = model.start_chat(
|
||||||
history=messages,
|
history=messages,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response = chat.send_message(message, stream=True)
|
response = chat.send_message(message, stream=True)
|
||||||
|
|
Loading…
Reference in a new issue