Jeyachandran configured and installed Ollama and given the URL (as given below)
Step 1: To Check the Ollama Running In browser Type
http://167.86.108.113:30007/
Response : Ollama is running
Step 2: in VS code run this Python Script:
import requestsimport timeimport json# Ollama server endpointurl = "https://immai.acintia.com/api/generate"# Prompt to testprompt = "Explain quantum computing in simple words"payload = {"model": "gemma3:4b","prompt": prompt,"stream": True # set to False if you want the whole output at once}# Start timerstart_time = time.time()response = requests.post(url, json=payload, stream=True)output_text = ""for line in response.iter_lines():if line:data = json.loads(line.decode("utf-8"))if "response" in data:output_text += data["response"]# End timerend_time = time.time()elapsed = end_time - start_timeprint("=== Prompt ===")print(prompt)print("\n=== Response ===")print(output_text.strip())print(f"\n⏱ Response time: {elapsed:.2f} seconds")
Response:PS F:\xampp\htdocs\wp-plugins\EduSite> & C:/Users/AURMC/AppData/Local/Microsoft/WindowsApps/python3.11.exe f:/xampp/htdocs/wp-plugins/EduSite/test.py === Prompt === Explain quantum computing in simple words === Response === Okay, let's break down quantum computing in a way that's hopefully easy to understand. It's a really complex field, but here’s the gist: **1. Regular Computers (Classical Computers):** * **Bits:** Think of a regular computer as using tiny switches that are either **on** (1) or **off** (0). Everything a regular computer does – from browsing the internet to playing games – is based on these 0s and 1s. * **One thing at a time:** A bit can only be in one state (0 or 1) at any given moment. It’s like a light switch – it's either on *or* off, but not both at the same time. **2. Quantum Computers:** * **Qubits:** Instead of bits, quantum computers use **qubits**. These are based on the weird rules of quantum mechanics. * **Superposition:** This is the key! A qubit can be **both 0 and 1 *at the same time***. Think of it like a spinning coin – it’s neither heads nor tails until you stop it and look. This "both at once" ability is called superposition. * **Entanglement:** This is even weirder. When two qubits are entangled, they become linked in a spooky way. If you measure the state of one, you instantly know the state of the other, no matter how far apart they are. **3. What does this all mean?** * **Massive Parallelism:** Because a qubit can be in multiple states at once, a quantum computer can explore many possibilities simultaneously. A regular computer has to try each option one after another. This allows quantum computers to potentially solve certain problems *much* faster than classical computers. * **Specific Problems:** Quantum computers aren't going to replace your laptop. They're designed for *specific* types of problems that are incredibly complex for classical computers. These include: * **Drug Discovery:** Simulating molecules to find new medicines. * **Materials Science:** Designing new materials with specific properties. **4. Analogy Time:** Imagine trying to find your way through a maze. * **Classical Computer:** You try one path, if it's a dead end, you backtrack and try another. * **Quantum Computer:** You explore *all* the paths simultaneously! **Important Note:** Quantum computing is still in its very early stages. Building and programming quantum computers is incredibly difficult. They are fragile and prone to errors. --- **Resources to learn more:** * **IBM Quantum Experience:** [https://quantum.ibm.com/](https://quantum.ibm.com/) – A great place to experiment with real quantum computers. * **Wikipedia - Quantum Computing:** [https://en.wikipedia.org/wiki/Quantum_computing](https://en.wikipedia.org/wiki/Quantum_computing) Do you want me to delve into a specific aspect of quantum computing, like: * Superposition in more detail? * Entanglement? * What types of problems are most suited for quantum computers?⏱ Response time: 158.22 seconds
After Changing URL (-ip address) add adding Marans prompt template Response + UIimport streamlit as stimport requestsimport timeimport json# Default Ollama server endpointDEFAULT_URL = "https://immai.acintia.com/api/generate"st.set_page_config(page_title="AI Legal Assistant (India)", layout="wide")st.title("⚖️ AI Legal Assistant (Indian Laws & Corporate Regulations)")# Sidebar for settingsst.sidebar.header("Settings")url = st.sidebar.text_input("Ollama API URL", DEFAULT_URL)model = st.sidebar.text_input("Model", "gemma3:4b")# ✅ Initialize conversation history in session stateif "history" not in st.session_state:st.session_state["history"] = []# Prompt inputquery = st.text_area("Enter your legal query:", height=100)# TemplatePROMPT_TEMPLATE = ("You are an AI Legal Assistant specialized only in Indian laws and corporate regulations. ""You must not answer any queries unrelated to Indian legal and corporate law. ""Provide a brief summary (2-3 bullet points) by default. If the user asks for more details, ""a deeper explanation, or a follow-up question, provide a thorough response based on the conversation history. ""Use **bold**, *italics*, bullet points (e.g., - Bullet), and emojis where appropriate. ""Current conversation:\n{history}\n""--- Examples ---\n""User: What are the documents required for private limited company registration in India?\n""Legal Assistant: \n""- **Identity Proof**: PAN card, passport, Aadhar card, or driver's license of all directors and shareholders.\n""- **Address Proof**: Voter ID, passport, or a recent utility bill (less than 2 months old).\n""- **Registered Office Proof**: Rent agreement or sale deed + NOC from landlord.\n""- **DIN** and **DSC** for all directors.\n\n""User: What is the weather like today in Tokyo?\n""Legal Assistant: I'm sorry, I can only provide information related to Indian laws and corporate regulations.\n""--- End of Examples ---\n""User: {query}\n\nLegal Assistant:")if st.button("Ask Legal Assistant"):if not query.strip():st.warning("⚠️ Please enter a query")else:# Format conversation historyhistory_str = "\n".join([f"User: {h['user']}\nLegal Assistant: {h['assistant']}" for h in st.session_state["history"]])# Final prompt with history + templatefinal_prompt = PROMPT_TEMPLATE.format(history=history_str, query=query)payload = {"model": model,"prompt": final_prompt,"stream": True}st.info("⏳ Generating response...")start_time = time.time()try:response = requests.post(url, json=payload, stream=True, timeout=600)output_text = ""text_box = st.empty()for line in response.iter_lines():if line:data = json.loads(line.decode("utf-8"))if "response" in data:output_text += data["response"]text_box.markdown(f"**Response (streaming):**\n\n{output_text}")end_time = time.time()elapsed = end_time - start_timest.success(f"✅ Done in {elapsed:.2f} seconds")# Store in historyst.session_state["history"].append({"user": query, "assistant": output_text.strip()})st.markdown("### Final Response")st.write(output_text.strip())except Exception as e:st.error(f"Error: {e}")# ✅ Safe check for history before showingif st.session_state.get("history"):st.markdown("## 📝 Conversation History")for h in st.session_state["history"]:st.markdown(f"**User:** {h['user']}")st.markdown(f"**Assistant:** {h['assistant']}")st.markdown("---")

No comments:
Post a Comment