Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Building an AI from scratch
#1
I am using Python

Code:
import requests
import json

class HistoricalAgent:
    def __init__(self, name, model_url):
        self.name = name
        self.url = model_url  # Your Server Blade IP (e.g., http://192.168.1.50:11434/api/generate)
       
        # --- THE "INTERNAL STATE" (This is what Vedal does) ---
        self.personality = "A gruff but curious 1880s blacksmith named Silas."
        self.mood = "Neutral"
        self.short_term_memory = [] # Last few things said
       
    def construct_prompt(self, user_input):
        # We "bake" the state into every request so the AI knows who it is
        full_prompt = f"""
        [SYSTEM INSTRUCTION]
        You are {self.name}. {self.personality}
        Current Mood: {self.mood}
        Recent History: {self.short_term_memory[-3:]}
       
        [USER INPUT]
        {user_input}
       
        [RESPONSE]
        """
        return full_prompt

    def think_and_speak(self, user_input):
        payload = {
            "model": "llama3", # Or your custom 1880s model on the blade
            "prompt": self.construct_prompt(user_input),
            "stream": False
        }
       
        try:
            # Talking to your server blade via local network
            response = requests.post(self.url, json=payload)
            reply = response.json().get("response", "...")
           
            # Update internal memory
            self.short_term_memory.append(f"User: {user_input}")
            self.short_term_memory.append(f"Silas: {reply}")
           
            return reply
        except Exception as e:
            return f"Lost connection to the brain: {e}"

if __name__ == "__main__":
    # Point this to your actual server blade IP
    silas = HistoricalAgent("Silas", "http://192.168.1.50:11434/api/generate")
   
    print(f"--- {silas.name} is standing by in the forge ---")
    while True:
        text = input("You: ")
        if text.lower() in ['exit', 'quit']: break
       
        print(f"\n{silas.name} is thinking...")
        print(f"{silas.name}: {silas.think_and_speak(text)}")
Reply


[-]
Quick Reply
Message
Type your reply to this message here.


Messages In This Thread
Building an AI from scratch - by admin - 03-29-2026, 02:07 AM
RE: Building an AI from scratch - by admin - 03-29-2026, 02:11 AM
RE: Building an AI from scratch - by admin - 03-29-2026, 02:15 AM
RE: Building an AI from scratch - by admin - 03-29-2026, 02:21 AM
RE: Building an AI from scratch - by admin - 04-12-2026, 12:20 AM
RE: Building an AI from scratch - by admin - 04-12-2026, 12:28 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)