Läser nu ut Ollama-modell från yaml-fil
This commit is contained in:
@@ -56,38 +56,46 @@ def configure():
|
||||
# envrionment variable
|
||||
####################################
|
||||
backend_api_ep = 'http://localhost:5005/api/chat' # Default API endpoint
|
||||
if isinstance(updated_config.get('backend'), dict): # Look for 'backend' key in config file
|
||||
if isinstance(updated_config['backend'].get('url'), str): # Look for 'url' key in config file
|
||||
if isinstance(updated_config.get('backend'), dict): # Look for 'backend' key
|
||||
if isinstance(updated_config['backend'].get('url'), str): # Look for 'url' key
|
||||
url = updated_config['backend'].get('url')
|
||||
if isinstance(updated_config['backend'].get('api'), str): # Look for 'api' key in config file
|
||||
if isinstance(updated_config['backend'].get('api'), str): # Look for 'api' key
|
||||
api = updated_config['backend'].get('api')
|
||||
backend_api_ep = url+api # Extract API endpoint if defined
|
||||
logger.debug("BE_API_ENDPOINT is set to '{}'".format(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)
|
||||
####################################
|
||||
if isinstance(updated_config.get('ollama'), dict): # Look for 'ollama' key
|
||||
if isinstance(updated_config['ollama'].get('model'), str): # Look for 'model' key
|
||||
model_to_use = updated_config['ollama'].get('model')
|
||||
global_state.set_llm(model_to_use)
|
||||
|
||||
return updated_config
|
||||
|
||||
|
||||
def start_frontend(config):
|
||||
parsed_url = urllib.parse.urlparse(config['frontend']['url'])
|
||||
hostname = parsed_url.netloc.split(':')[0] # Split by ':' and take the first part, i.e., 'localhost', IP, or domain name
|
||||
port = parsed_url.port # This is the server port
|
||||
# def start_frontend(config):
|
||||
# parsed_url = urllib.parse.urlparse(config['frontend']['url'])
|
||||
# hostname = parsed_url.netloc.split(':')[0] # Split by ':' and take the first part, i.e., 'localhost', IP, or domain name
|
||||
# port = parsed_url.port # This is the server port
|
||||
|
||||
# Use the socket module in Python to check whether a port is in use,
|
||||
# which would indicate that a server is already running on that port.
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.bind((hostname, port))
|
||||
logger.debug("No server is running on %s -— starting one.", parsed_url.netloc)
|
||||
# Start frontend (web server) as a separate process
|
||||
subprocess.Popen(["python", "-m", "http.server", str(port)])
|
||||
except socket.error as e:
|
||||
if e.errno == 48:
|
||||
logger.debug("A server is already running on %s -— will use this.", parsed_url.netloc)
|
||||
else:
|
||||
raise # Unexpected error, re-raise it so we can see the traceback
|
||||
except Exception as e:
|
||||
logger.error("Failed to start frontend: %s", str(e)) # Corresponds to print(f"Failed to start frontend: {e}")
|
||||
# # Use the socket module in Python to check whether a port is in use,
|
||||
# # which would indicate that a server is already running on that port.
|
||||
# with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
# try:
|
||||
# s.bind((hostname, port))
|
||||
# logger.debug("No server is running on %s -— starting one.", parsed_url.netloc)
|
||||
# # Start frontend (web server) as a separate process
|
||||
# subprocess.Popen(["python", "-m", "http.server", str(port)])
|
||||
# except socket.error as e:
|
||||
# if e.errno == 48:
|
||||
# logger.debug("A server is already running on %s -— will use this.", parsed_url.netloc)
|
||||
# else:
|
||||
# raise # Unexpected error, re-raise it so we can see the traceback
|
||||
# except Exception as e:
|
||||
# logger.error("Failed to start frontend: %s", str(e)) # Corresponds to print(f"Failed to start frontend: {e}")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user