Loading, please wait...

VTU Circulars & Notifications

VTU Exam Circulars & Notifications

VTU Exam Time Table

VTU Academic Calendar

BAIL657C Program 8

8. Install langchain, cohere (for key), langchain-community. Get the api key( By logging into Cohere and obtaining the cohere key). Load a text document from your google drive . Create a prompt template to display the output in a particular manner.

PROGRAM:

# Module or library install command (run this in terminal before running the script)
#pip install langchain langchain-core langchain-community langchain-cohere cohere
import os
from langchain_community.document_loaders import TextLoader
from langchain_core.prompts import PromptTemplate
from langchain_cohere import ChatCohere


# =========================
# CONFIG
# =========================

COHERE_API_KEY = "Enter your cohere API key here"
FILE_PATH = "./teaching.txt"   # keep file in same folder

os.environ["COHERE_API_KEY"] = COHERE_API_KEY

# =========================
# LOAD FILE
# =========================

loader = TextLoader(FILE_PATH)
docs = loader.load()

document_text = docs[0].page_content

print("✅ File Loaded Successfully\n")
print("Preview:\n", document_text[:200], "\n")


# =========================
# PROMPT
# =========================

prompt = PromptTemplate(
    input_variables=["document", "question"],
    template="""
You are a helpful assistant. Read the document and answer.

Document: {document}
Question: {question}

Answer in this format:
Summary   : (1-2 sentences)
Answer    : (direct answer)
Key Points: (3 bullet points)
"""
)


# =========================
# MODEL
# =========================

llm = ChatCohere(
    model="command-a-03-2025",
    temperature=0.3
)

chain = prompt | llm


# =========================
# INTERACTIVE CHAT
# =========================

print("✅ Chat ready! Type 'exit' to quit.\n")

while True:
    question = input("You: ")

    if question.lower() == "exit":
        break

    result = chain.invoke({
        "document": document_text,
        "question": question
    })

    print("\nBot:")
    print(result.content)
    print()

OUTPUT:

✅ File Loaded Successfully

Preview:
 Teaching is the process of facilitating learning. A teacher helps students to acquire knowledge, skills, values, and habits.

Effective teaching involves clear communication, understanding student nee 

✅ Chat ready! Type 'exit' to quit.

You: What are the methods of teaching?

Bot:
Summary: Teaching methods are diverse strategies used by educators to facilitate learning, aiming to engage students and enhance their understanding and retention of knowledge. These methods vary depending on the subject, students' needs, and the teacher's approach.

Answer: Methods of teaching include examples, discussions, practical activities, online classes, videos, and interactive tools.

Key Points:
* Clear communication is essential for effective teaching, ensuring students understand the material.
* Teachers should adapt their methods to meet the diverse needs of their students, promoting a positive and engaging learning environment.
* Modern teaching incorporates technology to enhance learning outcomes, offering new opportunities for interaction and engagement.

You: 
Syllabus Papers
SGPA CGPA