-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
31 lines (24 loc) · 865 Bytes
/
app.py
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
import os
from dotenv import load_dotenv
from langchain_community.llms import Ollama
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
import streamlit as st
load_dotenv()
os.environ["LANGUAGE_API_KEY"] = os.getenv("LANGUAGE_API_KEY")
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_PROJECT"] = os.getenv("LANGCHAIN_PROJECT")
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant Kindly respond to the question asked."),
("user", "Question: {question}"),
]
)
st.title("Chat with Ollama:gemma2:2b")
input_text = st.text_input("Enter your question here: ")
llm = Ollama(model="gemma2:2b")
output_parser = StrOutputParser()
chain = prompt|llm|output_parser
if input_text:
st.write(chain.invoke({"question": input_text})
)