forked from React-Group/interstellar_ai
Compare commits
No commits in common. "3b5796cae67c0d3c0ea1a9abeace6d3c45424224" and "12e8e07d576999d84e9d86ac7d16fc1e90fec44f" have entirely different histories.
3b5796cae6
...
12e8e07d57
9 changed files with 67 additions and 147 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -34,5 +34,3 @@ yarn-error.log*
|
||||||
# typescript
|
# typescript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
api_key.txt
|
|
|
@ -7,7 +7,7 @@ interface ConversationProps {
|
||||||
onCopyClick: () => void;
|
onCopyClick: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>(
|
const Conversation = React.forwardRef<HTMLDivElement, ConversationProps>(
|
||||||
({ messages, onResendClick, onEditClick, onCopyClick }, ref: ForwardedRef<HTMLDivElement>) => {
|
({ messages, onResendClick, onEditClick, onCopyClick }, ref: ForwardedRef<HTMLDivElement>) => {
|
||||||
return (
|
return (
|
||||||
<div className="output">
|
<div className="output">
|
||||||
|
@ -40,4 +40,4 @@ const ConversationFrontend = React.forwardRef<HTMLDivElement, ConversationProps>
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export default ConversationFrontend;
|
export default Conversation;
|
|
@ -1,76 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
import InputFrontend from './InputFrontend';
|
|
||||||
import ConversationFrontend from './ConversationFrontend';
|
|
||||||
import { Mistral } from '@mistralai/mistralai';
|
|
||||||
|
|
||||||
async function prompt_mistral(model: string, prompt: string, system: string) {
|
|
||||||
const apiKey = "m3kZRjN8DRSIo88r8Iti9hmKGWIklrLY";
|
|
||||||
|
|
||||||
const client = new Mistral({ apiKey: apiKey });
|
|
||||||
|
|
||||||
var chatResponse = await client.chat.complete({
|
|
||||||
model: model,
|
|
||||||
messages: [{ role: 'user', content: prompt }, { role: 'system', content: system, }],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (chatResponse && chatResponse.choices && chatResponse.choices.length > 0) {
|
|
||||||
if (chatResponse.choices[0].message.content) {
|
|
||||||
messages.push('AI: ', chatResponse.choices[0].message.content);
|
|
||||||
console.error('Error: Brain Not Found');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.error('Error: Unexpected API response:', chatResponse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSendClick = (message: string) => {
|
|
||||||
messages.push('User: ', message);
|
|
||||||
prompt_mistral("mistral-large-latest", message, "You are a helpful assistant.")
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleMicClick = () => {
|
|
||||||
console.log('Mic clicked!');
|
|
||||||
// Do something when the mic button is clicked
|
|
||||||
};
|
|
||||||
|
|
||||||
var messages = [
|
|
||||||
'User: Hello!',
|
|
||||||
'AI: Hi there!',
|
|
||||||
'User: How are you?',
|
|
||||||
'AI: I’m good, thank you!'
|
|
||||||
];
|
|
||||||
|
|
||||||
const handleResendClick = () => {
|
|
||||||
console.log('Resend button clicked');
|
|
||||||
// Handle resend action
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEditClick = () => {
|
|
||||||
console.log('Edit button clicked');
|
|
||||||
// Handle edit action
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCopyClick = () => {
|
|
||||||
console.log('Copy button clicked');
|
|
||||||
// Handle copy action
|
|
||||||
};
|
|
||||||
|
|
||||||
const InputBackend = () => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<ConversationFrontend
|
|
||||||
messages={messages}
|
|
||||||
onResendClick={handleResendClick}
|
|
||||||
onEditClick={handleEditClick}
|
|
||||||
onCopyClick={handleCopyClick}
|
|
||||||
/>
|
|
||||||
<InputFrontend
|
|
||||||
message=""
|
|
||||||
onSendClick={handleSendClick}
|
|
||||||
onMicClick={handleMicClick}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default InputBackend;
|
|
21
app/InputForm.tsx
Normal file
21
app/InputForm.tsx
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const InputForm: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<form className="input" method="POST" action="" id="inputForm">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="user_message"
|
||||||
|
placeholder="Type your message here..."
|
||||||
|
/>
|
||||||
|
<button type="submit" name="option" value="chat">
|
||||||
|
<img src="/img/send.svg" alt="send" />
|
||||||
|
</button>
|
||||||
|
<button type="submit" name="option" value="voice">
|
||||||
|
<img src="/img/microphone.svg" alt="microphone" />
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InputForm;
|
|
@ -1,37 +0,0 @@
|
||||||
import React, { useState, ForwardedRef } from 'react';
|
|
||||||
|
|
||||||
interface InputProps {
|
|
||||||
message: string;
|
|
||||||
onSendClick: (message: string) => void;
|
|
||||||
onMicClick: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
|
|
||||||
({ message, onSendClick, onMicClick }, ref: ForwardedRef<HTMLDivElement>) => {
|
|
||||||
const [inputValue, setInputValue] = useState('');
|
|
||||||
|
|
||||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
setInputValue(e.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="input" id="inputForm">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
name="user_message"
|
|
||||||
placeholder="Type your message here..."
|
|
||||||
value={inputValue}
|
|
||||||
onChange={handleInputChange}
|
|
||||||
/>
|
|
||||||
<button type="submit" onClick={() => onSendClick(inputValue)}>
|
|
||||||
<img src="/img/send.svg" alt="send" />
|
|
||||||
</button>
|
|
||||||
<button type="submit" onClick={onMicClick}>
|
|
||||||
<img src="/img/microphone.svg" alt="microphone" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default InputFrontend;
|
|
12
app/backend/ai_api.ts
Normal file
12
app/backend/ai_api.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import ollama from 'ollama'
|
||||||
|
|
||||||
|
async function name(model: string, prompt: string, system: string,) {
|
||||||
|
var message = [{ role: 'user', content: prompt }, { role: 'system', content: system }]
|
||||||
|
var response = await ollama.chat({ model: model, messages: message, stream: true })
|
||||||
|
for await (const part of response) {
|
||||||
|
process.stdout.write(part.message.content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
34
app/page.tsx
34
app/page.tsx
|
@ -4,7 +4,8 @@ import React, { useState, useEffect, useRef } from 'react';
|
||||||
import Header from './Header';
|
import Header from './Header';
|
||||||
import History from './History';
|
import History from './History';
|
||||||
import Models from './Models';
|
import Models from './Models';
|
||||||
import InputBackend from './InputBackend';
|
import Conversation from './Conversation';
|
||||||
|
import InputForm from './InputForm';
|
||||||
import './styles/master.css';
|
import './styles/master.css';
|
||||||
|
|
||||||
const LandingPage: React.FC = () => {
|
const LandingPage: React.FC = () => {
|
||||||
|
@ -40,6 +41,28 @@ const LandingPage: React.FC = () => {
|
||||||
setShowDivs(prevState => !prevState);
|
setShowDivs(prevState => !prevState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const messages = [
|
||||||
|
'User: Hello!',
|
||||||
|
'AI: Hi there!',
|
||||||
|
'User: How are you?',
|
||||||
|
'AI: I’m good, thank you!'
|
||||||
|
];
|
||||||
|
|
||||||
|
const handleResendClick = () => {
|
||||||
|
console.log('Resend button clicked');
|
||||||
|
// Handle resend action
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEditClick = () => {
|
||||||
|
console.log('Edit button clicked');
|
||||||
|
// Handle edit action
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCopyClick = () => {
|
||||||
|
console.log('Copy button clicked');
|
||||||
|
// Handle copy action
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Header toggleDivs={toggleDivs} showDivs={showDivs} />
|
<Header toggleDivs={toggleDivs} showDivs={showDivs} />
|
||||||
|
@ -49,7 +72,14 @@ const LandingPage: React.FC = () => {
|
||||||
<Models />
|
<Models />
|
||||||
</div>
|
</div>
|
||||||
<div className={`conversation-container ${showDivs ? 'expanded' : 'collapsed'}`}>
|
<div className={`conversation-container ${showDivs ? 'expanded' : 'collapsed'}`}>
|
||||||
<InputBackend />
|
<Conversation
|
||||||
|
ref={conversationRef}
|
||||||
|
messages={messages}
|
||||||
|
onResendClick={handleResendClick}
|
||||||
|
onEditClick={handleEditClick}
|
||||||
|
onCopyClick={handleCopyClick}
|
||||||
|
/>
|
||||||
|
<InputForm />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
26
package-lock.json
generated
26
package-lock.json
generated
|
@ -8,8 +8,6 @@
|
||||||
"name": "interstellar_ai",
|
"name": "interstellar_ai",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mistralai/mistralai": "^1.0.4",
|
|
||||||
"fs": "^0.0.1-security",
|
|
||||||
"next": "14.2.12",
|
"next": "14.2.12",
|
||||||
"ollama": "^0.5.9",
|
"ollama": "^0.5.9",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
@ -237,14 +235,6 @@
|
||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mistralai/mistralai": {
|
|
||||||
"version": "1.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/@mistralai/mistralai/-/mistralai-1.0.4.tgz",
|
|
||||||
"integrity": "sha512-fLFBD8r4KvITCkKlKcq2ievnNyLd7Oob4xMY7MkY04BqR4nffkTS49DqapnVkemuldtrmHidwPzwD7UT+yFC4A==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"zod": ">= 3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@next/env": {
|
"node_modules/@next/env": {
|
||||||
"version": "14.2.12",
|
"version": "14.2.12",
|
||||||
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.12.tgz",
|
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.12.tgz",
|
||||||
|
@ -2333,12 +2323,6 @@
|
||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fs": {
|
|
||||||
"version": "0.0.1-security",
|
|
||||||
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
|
||||||
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==",
|
|
||||||
"license": "ISC"
|
|
||||||
},
|
|
||||||
"node_modules/fs.realpath": {
|
"node_modules/fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||||
|
@ -5335,16 +5319,6 @@
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"node_modules/zod": {
|
|
||||||
"version": "3.23.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz",
|
|
||||||
"integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==",
|
|
||||||
"license": "MIT",
|
|
||||||
"peer": true,
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sponsors/colinhacks"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mistralai/mistralai": "^1.0.4",
|
|
||||||
"fs": "^0.0.1-security",
|
|
||||||
"next": "14.2.12",
|
"next": "14.2.12",
|
||||||
"ollama": "^0.5.9",
|
"ollama": "^0.5.9",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
|
Loading…
Reference in a new issue