![]() |
A Chat script - Printable Version +- Todd Daugherty's N9OGL Official Board (http://160.32.227.211/n9ogl) +-- Forum: General (http://160.32.227.211/n9ogl/forumdisplay.php?fid=1) +--- Forum: Main Board (http://160.32.227.211/n9ogl/forumdisplay.php?fid=2) +--- Thread: A Chat script (/showthread.php?tid=228) |
A Chat script - admin - 04-07-2025 this is a AI chat script that I've been working on which uses LLM Studio locally on your computer for free. It connects to LLM studio where it uses the Dataset. It will use any dataset you want just make sure that LLM Studio API is turned on and listening to port 5000. import requests # Set up the local LLM Studio API endpoint (modify based on your setup) LLM_STUDIO_API_URL = "http://localhost:5000/chat" # Example URL, modify as needed def chat_with_llm(prompt): response = requests.post(LLM_STUDIO_API_URL, json={"input": prompt}) if response.status_code == 200: return response.json().get("output", "").strip() else: return "Error: Failed to connect to LLM Studio." if __name__ == "__main__": while True: human_input = input("Human: ") if human_input.lower() in ["quit", "exit", "bye"]: break response = chat_with_llm(human_input) print("Chatbot:", response) RE: A Chat script - admin - 04-07-2025 Here, is a JavaScript to allow you to connect to it anywhere via a web browser <script> async function chat() { let userInput = document.getElementById("message").value; let response = await fetch("https://your-server.com/chat", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({"input": userInput}) }); let data = await response.json(); document.getElementById("response").innerText = data.response; } </script> RE: A Chat script - admin - 04-07-2025 (04-07-2025, 05:48 PM)admin Wrote: Here, is a JavaScript to allow you to connect to it anywhere via a web browser Change "https://your-server.com/chat" to your website or address/chat RE: A Chat script - admin - 04-07-2025 Since the chatbot uses Python, FastAPI or Flask can be great choices for creating a simple API. like this: from flask import Flask, request, jsonify app = Flask(__name__) @app.route("/chat", methods=["POST"]) def chat(): user_input = request.json.get("input", "") response = chat_with_llm(user_input) # Call your chatbot function return jsonify({"response": response}) if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) # Adjust the port as needed RE: A Chat script - admin - 04-07-2025 I was up till 5AM this morning working on it. |