From d01d81a6d7b184f43d4be2191ff89e3792813f71 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 24 Oct 2024 19:21:23 -0700 Subject: [PATCH] openWebUI --- modules/llm.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/llm.py b/modules/llm.py index 138b554..4ffb113 100644 --- a/modules/llm.py +++ b/modules/llm.py @@ -9,8 +9,19 @@ from modules.log import * from ollama import Client as OllamaClient from googlesearch import search # pip install googlesearch-python +# enahanced workflow with OpenWebUI +openWebUI = False + +# This is my attempt at a simple RAG implementation it will require some setup +# you will need to have the RAG data in a folder named rag in the data directory (../data/rag) +# This is lighter weight and can be used in a standalone environment, needs chromadb ragDEV = False +if openWebUI: + import requests + openWebUI_api_key = "your_api_key" + openWebUI_base_url = "http://localhost:3000/api/v1" + if ragDEV: import os import ollama # pip install ollama @@ -134,6 +145,18 @@ def query_collection(prompt): data = results['documents'][0][0] return data +def llm_query_openWebUI(input, nodeID=0, location_name=None): + # passes the message-rx to the OpenWebUI API directly + headers = {"Authorization": f"Bearer {openWebUI_api_key}"} + data = {"model": llmModel, "prompt": input} + response = requests.post(f"{openWebUI_base_url}/chat/completions", headers=headers, json=data) + + if response.status_code == 200: + return response.json()["choices"][0]["message"]["content"] + else: + logger.debug(f"System: LLM: {response.status_code} - {response.text}") + return "I am having trouble processing your request, please try again later." + def llm_query(input, nodeID=0, location_name=None): global antiFloodLLM, llmChat_history googleResults = []