Spaces:
Running
Running
File size: 1,154 Bytes
4116826 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from vector import retriever
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
# Load the LLM using OpenRouter with simplified configuration
model = ChatOpenAI(
api_key=os.getenv("OPENROUTER_API_KEY"),
base_url="https://openrouter.ai/api/v1",
model="openai/gpt-3.5-turbo" # Using a model supported by OpenRouter
)
# Prompt template customized for CVE Q&A
template = """
You are a cybersecurity expert trained to answer questions about software vulnerabilities using CVE data.
Here are some relevant CVE entries:
{reviews}
Here is the question to answer:
{question}
"""
prompt = ChatPromptTemplate.from_template(template)
chain = prompt | model
# Interactive Q&A loop
while True:
print("\n\n-------------------------------")
question = input("Ask your cybersecurity question (q to quit): ")
print("\n\n")
if question.lower() == "q":
break
reviews = retriever.invoke(question)
result = chain.invoke({"reviews": reviews, "question": question})
print(result.content)
|