DA1212 commited on
Commit
aa34426
1 Parent(s): b66a97f

Upload ollama.py

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