Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Chat script
#1
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)
Reply
#2
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>
Reply
#3
(04-07-2025, 05:48 PM)admin Wrote: 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>
 
Change "https://your-server.com/chat" to your website or address/chat
Reply
#4
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
Reply
#5
I was up till 5AM this morning working on it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)