Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ee7ae520f | |||
| 1f6f0a72d5 | |||
| 9e6e6048f3 | |||
| 538f02e6a7 | |||
| 810b369721 |
@@ -1,22 +1,40 @@
|
||||
# Frontend Configuration
|
||||
frontend:
|
||||
url: "http://localhost:5004"
|
||||
# frontend:
|
||||
# url: "http://localhost:5004"
|
||||
|
||||
# Backend Configuration
|
||||
backend:
|
||||
url: "http://localhost:5004"
|
||||
api: "/api/chat"
|
||||
|
||||
|
||||
models:
|
||||
- model: "AUTODETECT"
|
||||
title: "Ollama"
|
||||
url: "http://localhost:11434"
|
||||
provider: "ollama"
|
||||
- model: "AUTODETECT"
|
||||
title: "Ollama-WARA"
|
||||
url: "https://ollama-test.wara-ops.org"
|
||||
requestOptions:
|
||||
headers:
|
||||
Authorization: "${OLLAMA_API_KEY}" # This should expand to something like "Basic XY...="
|
||||
provider: "ollama"
|
||||
|
||||
# Ollama Server Configuration
|
||||
ollama:
|
||||
title: "Ollama-local"
|
||||
url: "http://localhost:11434"
|
||||
api_key: "${OLLAMA_API_KEY}" # Refer to environment variable
|
||||
model: "phi3:mini" # Select a model supported by the Ollama server
|
||||
# model: "llama3:70b" # Select a model supported by the Ollama server
|
||||
# model: "llama3.1:70b" # Select a model supported by the Ollama server
|
||||
# model: "llama3.1:8b" # Select a model supported by the Ollama server
|
||||
# model: "llama3:latest" # Select a model supported by the Ollama server
|
||||
# model: "mannix/llama3-8b-ablitered-v3:latest" # Select a model supported by the Ollama server
|
||||
# model: "mistral-nemo:latest" # Select a model supported by the Ollama server
|
||||
# model: "gemma2:27b"
|
||||
# model: "AUTODETECT"
|
||||
|
||||
# Logging – comment out the whole section for default level which is INFO
|
||||
logging:
|
||||
|
||||
@@ -6,35 +6,15 @@
|
||||
<link rel="stylesheet" href="/css/clientstyle.css">
|
||||
<!-- <link rel="stylesheet" href="python_test/smartassist/src/css/clientstyle.css"> -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Ollama Chat</h1>
|
||||
<div id="chatbox">
|
||||
<!-- messages will be rendered here -->
|
||||
</div>
|
||||
<textarea id="userInput" placeholder="Type your message..." rows="5"></textarea>
|
||||
<button id="sendButton" onclick="sendMessage()">Send</button>
|
||||
<button id="sendButton" onclick="window.frontendApi.sendMessage()">Send</button>
|
||||
|
||||
<!-- Get the apiEndpoint and the useModel -->
|
||||
<!-- <script>
|
||||
const apiEndpoint = window.apiEndpoint;
|
||||
const useModel = window.useModel;
|
||||
console.log("client.html - API Endpoint: ", apiEndpoint);
|
||||
console.log("client.html - use model: ", useModel);
|
||||
</script> -->
|
||||
|
||||
<!-- <script>
|
||||
let apiEndpoint; // Make variable available outside of the scope of the event listener
|
||||
let useModel; // Make variable available outside of the scope of the event listener
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.origin === 'http://localhost:5004') { // Make sure this matches your origin
|
||||
const { apiEndpoint, useModel } = event.data;
|
||||
console.log("client.html - API Endpoint: ", apiEndpoint);
|
||||
console.log("client.html - use model: ", useModel);
|
||||
window.apiEndpoint = apiEndpoint;
|
||||
window.useModel = useModel;
|
||||
}
|
||||
});
|
||||
</script> -->
|
||||
|
||||
<!-- Marked-it for markdown rendering -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/dist/markdown-it.min.js"></script>
|
||||
@@ -54,9 +34,6 @@
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
const chatContainer = document.getElementById('chatbox');
|
||||
|
||||
|
||||
@@ -31,15 +31,22 @@ def configure():
|
||||
return os.getenv(env_var_name, None)
|
||||
return value
|
||||
|
||||
def update_dict_with_env_vars(d):
|
||||
for key in d:
|
||||
if isinstance(d[key], dict):
|
||||
update_dict_with_env_vars(d[key]) # Recursively check nested dictionaries
|
||||
elif isinstance(d[key], str):
|
||||
d[key] = resolve_env_var(d[key])
|
||||
def update_value(value):
|
||||
if isinstance(value, dict): # Dictionaries need recursive check
|
||||
return update_dict_with_env_vars(value)
|
||||
elif isinstance(value, list): # Lists must be traversed element by element
|
||||
return [update_value(item) for item in value]
|
||||
elif isinstance(value, str): # If value is a string it might be an environmnet variable
|
||||
return resolve_env_var(value)
|
||||
else: # Anything else, just keep the old value
|
||||
return value
|
||||
|
||||
def update_dict_with_env_vars(d): # Check all keys in d
|
||||
for key in d: # Iterate over all keys in the dictionary. The keys seen are all at the same level
|
||||
logger.info(f"key investigated now: {key}")
|
||||
d[key] = update_value(d[key])
|
||||
return d
|
||||
|
||||
# Update the config dictionary with resolved environment variables
|
||||
updated_config = update_dict_with_env_vars(config)
|
||||
|
||||
####################################
|
||||
@@ -64,7 +71,6 @@ def configure():
|
||||
logger.debug(f"Constructing endpoint address as url+api: {url+api}")
|
||||
global_state.set_backend_api_ep(url+api) # Extract API endpoint if defined and set in global_state
|
||||
logger.debug(f"Backend API endpoint is set to {global_state.get_backend_api_ep()}")
|
||||
# os.environ['BE_API_ENDPOINT'] = backend_api_ep # Look into alternative way to share this with backend.py
|
||||
|
||||
####################################
|
||||
# Extract Ollama parameters (url, api_key, model)
|
||||
|
||||
@@ -61,7 +61,7 @@ h1 {
|
||||
border-color: #66afe9; /* Blue outline on focus */
|
||||
}
|
||||
|
||||
button[onclick="sendMessage()"] {
|
||||
button[onclick="window.frontendApi.sendMessage()"] {
|
||||
background-color: #4CAF50; /* Green */
|
||||
border: none;
|
||||
color: white;
|
||||
@@ -75,11 +75,11 @@ button[onclick="sendMessage()"] {
|
||||
transition: background-color 0.3s; /* Smooth transition effect */
|
||||
}
|
||||
|
||||
button[onclick="sendMessage()"]:hover {
|
||||
button[onclick="window.frontendApi.sendMessage()"]:hover {
|
||||
background-color: #b2b2b2; /* Light Grey on hover */
|
||||
}
|
||||
|
||||
button[onclick="sendMessage()"]:active {
|
||||
button[onclick="window.frontendApi.sendMessage()"]:active {
|
||||
background-color: #6f6f6f; /* Dark Grey when clicked */
|
||||
}
|
||||
|
||||
|
||||
@@ -1,111 +1,3 @@
|
||||
|
||||
// // Get the user input element from the DOM
|
||||
// const chatbox = document.getElementById('chatbox');
|
||||
// const userInput = document.getElementById('userInput');
|
||||
|
||||
// const parser = window.markdownit({
|
||||
// linkify: true,
|
||||
// strikethrough: true,
|
||||
// });
|
||||
|
||||
// parser.enable(['table']);
|
||||
|
||||
// // const apiEndpoint = window.apiEndpoint; // Get the API endpoint
|
||||
// // const useModel = window.useModel; // Get whether to use a model or not
|
||||
// // console.log("frontend.js - API Endpoint: ", window.apiEndpoint);
|
||||
// // console.log("frontend.js - Use model: ", window.useModel);
|
||||
|
||||
// let apiEndpoint; // Make variable available outside of the scope of the event listener
|
||||
// let useModel; // Make variable available outside of the scope of the event listener
|
||||
// window.addEventListener('message', function(event) {
|
||||
// if (event.origin === 'http://localhost:5004') { // Make sure this matches your origin
|
||||
// const { apiEndpoint, useModel } = event.data;
|
||||
// console.log("client.html - API Endpoint: ", apiEndpoint);
|
||||
// console.log("client.html - use model: ", useModel);
|
||||
// window.apiEndpoint = apiEndpoint;
|
||||
// window.useModel = useModel;
|
||||
// }
|
||||
// });
|
||||
|
||||
// console.log("frontend.js - API Endpoint: ", window.apiEndpoint);
|
||||
// console.log("frontend.js - Use model: ", window.useModel);
|
||||
|
||||
// // Define a function to send the user's message to the AI
|
||||
// function sendMessage() {
|
||||
// // Get the user's input message and trim any whitespace
|
||||
// const query = userInput.value.trim();
|
||||
|
||||
// // Check if the message is not empty
|
||||
// if (query !== '') {
|
||||
|
||||
// // fetch(`${apiEndpoint}`, {
|
||||
// fetch(apiEndpoint, {
|
||||
// method: 'POST',
|
||||
// headers: { 'Content-Type': 'application/json' },
|
||||
// body: JSON.stringify({ query, model: useModel }), // Add these parameters here
|
||||
// // body: JSON.stringify({ query, url_server: "http://your-custom-url", model: "phi3:mini" }), // Add these parameters here
|
||||
// })
|
||||
// .then(response => response.json())
|
||||
// .then(data => {
|
||||
// // Get the AI's response from the API data
|
||||
// const aiResponse = data.response;
|
||||
|
||||
// // Render the user's original message in the chatbox
|
||||
// renderMessage(query, 'user-message');
|
||||
|
||||
// // Render the AI's response in the chatbox
|
||||
// renderMessage(aiResponse, 'ai-response');
|
||||
|
||||
// // Clear the user input field for the next message
|
||||
// userInput.value = '';
|
||||
// })
|
||||
// .catch(error => console.error('Error sending message:', error));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// // Define a function to render a message in the chatbox with a specific class name
|
||||
// function renderMessage(text, className) {
|
||||
// // Create a new div element to hold the message
|
||||
// const messageElement = document.createElement('div');
|
||||
|
||||
// // Add the specified class name to the element
|
||||
// messageElement.className = className;
|
||||
|
||||
// // // Set the text content of the element to the message text
|
||||
// // messageElement.textContent = text;
|
||||
|
||||
// // Use the markdown-it parser
|
||||
// const html = parser.render(text);
|
||||
// messageElement.innerHTML = html;
|
||||
|
||||
// // Append the message element to the chatbox immediately
|
||||
// // chatbox.appendChild(messageElement);
|
||||
|
||||
// // Typeset math in the message element
|
||||
// MathJax.typesetPromise([messageElement]).then(() => {
|
||||
// // No need to append anything here, it's already appended above
|
||||
// chatbox.appendChild(messageElement);
|
||||
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Make the button toggle colour when user presses Enter on keyboard
|
||||
// const sendButton = document.getElementById('sendButton');
|
||||
|
||||
// document.addEventListener('keydown', function(event) {
|
||||
// if (event.key === 'Enter') {
|
||||
// sendButton.style.backgroundColor = '#6f6f6f'; // Dark Grey when Enter is pressed
|
||||
// }
|
||||
// });
|
||||
|
||||
// document.addEventListener('keyup', function() {
|
||||
// sendButton.style.backgroundColor = ''; // Restore the original style when any key is released
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// Get the user input element from the DOM
|
||||
const chatbox = document.getElementById('chatbox');
|
||||
const userInput = document.getElementById('userInput');
|
||||
|
||||
Reference in New Issue
Block a user