3 Commits

Author SHA1 Message Date
Joakim Persson ab23585711 Testar uttökad yaml-konfiguration 2024-08-01 17:04:25 +02:00
Joakim Persson 916b6f9e52 Testar med fjärrserver för ollama. Endast tillfällig lösning. 2024-08-01 17:03:25 +02:00
Joakim Persson cfed550a3e Lagt till backend och modules från yaml-filen 2024-08-01 17:02:20 +02:00
3 changed files with 41 additions and 15 deletions
+6 -4
View File
@@ -13,22 +13,24 @@ models:
title: "Ollama" title: "Ollama"
url: "http://localhost:11434" url: "http://localhost:11434"
provider: "ollama" provider: "ollama"
# - model: "AUTODETECT"
- model: "AUTODETECT" - model: "AUTODETECT"
title: "Ollama-WARA" title: "Ollama-WARA"
url: "https://ollama-test.wara-ops.org" url: "https://ollama-test.wara-ops.org"
requestOptions: requestOptions:
headers: headers:
Authorization: "${OLLAMA_API_KEY}" # This should expand to something like "Basic XY...=" Authorization: "${OLLAMA_API_KEY}" # on MacOS: echo "Authorization: Basic $(echo -n 'user:password' | gbase64 -w 0)"
provider: "ollama" provider: "ollama"
# Ollama Server Configuration # Ollama Server Configuration
ollama: ollama:
title: "Ollama-local" title: "Ollama-local"
url: "http://localhost:11434" # url: "http://localhost:11434"
url: "https://ollama-test.wara-ops.org"
api_key: "${OLLAMA_API_KEY}" # Refer to environment variable api_key: "${OLLAMA_API_KEY}" # Refer to environment variable
model: "phi3:mini" # Select a model supported by the Ollama server # model: "phi3:mini" # Select a model supported by the Ollama server
# model: "llama3:70b" # 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:70b" # Select a model supported by the Ollama server
# model: "llama3.1:8b" # 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: "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: "mannix/llama3-8b-ablitered-v3:latest" # Select a model supported by the Ollama server
+13 -11
View File
@@ -58,15 +58,15 @@ def set_session():
resp.set_cookie('session', 'some-value', samesite='None', secure=True) # Add SameSite attribute here resp.set_cookie('session', 'some-value', samesite='None', secure=True) # Add SameSite attribute here
return resp return resp
@app.route('/profile') # @app.route('/profile')
def profile(): # def profile():
# Retrieve data from the session # # Retrieve data from the session
user_id = session.get('user_id') # user_id = session.get('user_id')
if user_id: # if user_id:
return f'User ID: {user_id}' # return f'User ID: {user_id}'
else: # else:
return 'No user ID found' # return 'No user ID found'
@app.route('/<path:filename>') @app.route('/<path:filename>')
@@ -89,7 +89,8 @@ CORS(app, resources={
@app.route('/api/chat', methods=['POST']) @app.route('/api/chat', methods=['POST'])
def chat(url_server = "http://localhost:11434/api/generate", model = "phi3:mini"): def chat(model = "phi3:mini"):
# def chat(url_server = "http://localhost:11434/api/generate", model = "phi3:mini"):
""" """
This function handles the chat. The frontend client (web browser) calls the This function handles the chat. The frontend client (web browser) calls the
backend server through this endpoint (/api/chat) that manage queries backend server through this endpoint (/api/chat) that manage queries
@@ -99,7 +100,7 @@ def chat(url_server = "http://localhost:11434/api/generate", model = "phi3:mini"
# Get the message from the JSON in the request body # Get the message from the JSON in the request body
data = request.get_json() data = request.get_json()
message = data.get('query') message = data.get('query')
url_server = data.get('url_server', url_server) # Use provided URL or default url_server = data.get('url_server', "https://ollama-test.wara-ops.org/api/generate") # Use provided URL or default
model = data.get('model', model) # Use provided model or default model = data.get('model', model) # Use provided model or default
# Get chat history from session storage (e.g., a dictionary) # Get chat history from session storage (e.g., a dictionary)
@@ -122,8 +123,9 @@ def chat(url_server = "http://localhost:11434/api/generate", model = "phi3:mini"
url = url_server url = url_server
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Authorization": "Basic ZWNzanBlcjoxM2JjMTU4ZDhmNmY5YTU4YTkzZDNmY2I="
} }
logger.debug(f"url: {url} headers: {headers}")
response = requests.post(url, response = requests.post(url,
headers=headers, headers=headers,
data=json.dumps(data_to_send)) data=json.dumps(data_to_send))
+22
View File
@@ -26,6 +26,11 @@ class GlobalState:
cls._instance.logger.info(" __new__(cls): Logger in GlobalState created: %s", cls._instance.logger) cls._instance.logger.info(" __new__(cls): Logger in GlobalState created: %s", cls._instance.logger)
cls._instance.llm = "phi3:mini" # Default LLM for queries. TODO: Check with ollama server that it actually exists cls._instance.llm = "phi3:mini" # Default LLM for queries. TODO: Check with ollama server that it actually exists
cls._instance.backend_api_ep = "http://localhost:5005/api/chat" # Default backend API endpoint cls._instance.backend_api_ep = "http://localhost:5005/api/chat" # Default backend API endpoint
# Try making things more aligned with the outline of the yaml file
cls._instance.backend = dict() # Holds info on which server the clients connect to
cls._instance.models = [] # A list that holds info on which models are available for use (server url, model name, provider et cetera)
# logging - already done in __new__, perhaps change layout later
return cls._instance return cls._instance
def configure_logging(self, level=None): def configure_logging(self, level=None):
@@ -73,3 +78,20 @@ class GlobalState:
"""Getter for backend API endpoint""" """Getter for backend API endpoint"""
return self.backend_api_ep return self.backend_api_ep
def set_backend(self, backend=None):
"""Set backend that web clients connect to"""
self.backend = backend
def get_backend(self):
"""Getter for backend that web clients connect to"""
return self.backend
def set_models(self, models=None):
"""Set the list of models."""
self.models = models
if not isinstance(models, list):
raise ValueError("Models must be a list")
def get_models(self):
"""Return the list of models"""
return self.models