Waseem771 commited on
Commit
3dadc3e
1 Parent(s): 38bea0a

Create ollama.py

Browse files
Files changed (1) hide show
  1. ollama.py +33 -0
ollama.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_openai import ChatOpenAI
2
+ from langchain_core.prompts import ChatPromptTemplate
3
+ from langchain_core.output_parsers import StrOutputParser
4
+ from langchain_community.llms import Ollama
5
+ import streamlit as st
6
+ import os
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ os.environ["LANGCHAIN_TRACING_V2"]="true"
12
+ os.environ["LANGCHAIN_API_KEY"]=os.getenv("LANGCHAIN_API_KEY")
13
+
14
+ ## Prompt Template
15
+
16
+ prompt=ChatPromptTemplate.from_messages(
17
+ [
18
+ ("system","You are a helpful assistant. Please response to the user queries"),
19
+ ("user","Question:{question}")
20
+ ]
21
+ )
22
+ ## streamlit framework
23
+
24
+ st.title('Langchain Demo With LLAMA2 API')
25
+ input_text=st.text_input("Search the topic u want")
26
+
27
+ # ollama LLAma2 LLm
28
+ llm=Ollama(model="llama2")
29
+ output_parser=StrOutputParser()
30
+ chain=prompt|llm|output_parser
31
+
32
+ if input_text:
33
+ st.write(chain.invoke({"question":input_text}))