AliZain1 commited on
Commit
6acd032
·
verified ·
1 Parent(s): eefe6b9

Upload 2 files

Browse files
Files changed (2) hide show
  1. example1.py +77 -0
  2. requirements.txt +4 -0
example1.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Integrate our code OpenAI API
2
+ import os
3
+ from constants import openai_key
4
+ from langchain import PromptTemplate
5
+ from langchain.chains import LLMChain
6
+
7
+ from langchain.memory import ConversationBufferMemory
8
+
9
+ from langchain.chains import SequentialChain
10
+
11
+ import streamlit as st
12
+
13
+
14
+ from langchain_groq import ChatGroq
15
+ import os
16
+
17
+ os.environ["GROQ_API_KEY"] = openai_key
18
+
19
+
20
+ #model = ChatGroq(model="llama3-8b-8192")
21
+ llm = ChatGroq(model="llama3-8b-8192", temperature=0.8)
22
+
23
+ # streamlit framework
24
+
25
+ st.title('Celebrity Search Results')
26
+ input_text=st.text_input("Search the topic u want")
27
+
28
+ # Prompt Templates
29
+
30
+ first_input_prompt=PromptTemplate(
31
+ input_variables=['name'],
32
+ template="Tell me about celebrity {name}"
33
+ )
34
+
35
+ # Memory
36
+
37
+ person_memory = ConversationBufferMemory(input_key='name', memory_key='chat_history')
38
+ dob_memory = ConversationBufferMemory(input_key='person', memory_key='chat_history')
39
+ descr_memory = ConversationBufferMemory(input_key='dob', memory_key='description_history')
40
+
41
+ ## OPENAI LLMS
42
+ #llm=ChatGroq(temperature=0.8)
43
+ chain=LLMChain(
44
+ llm=llm,prompt=first_input_prompt,verbose=True,output_key='person',memory=person_memory)
45
+
46
+ # Prompt Templates
47
+
48
+ second_input_prompt=PromptTemplate(
49
+ input_variables=['person'],
50
+ template="when was {person} born"
51
+ )
52
+
53
+ chain2=LLMChain(
54
+ llm=llm,prompt=second_input_prompt,verbose=True,output_key='dob',memory=dob_memory)
55
+ # Prompt Templates
56
+
57
+ third_input_prompt=PromptTemplate(
58
+ input_variables=['dob'],
59
+ template="Mention 5 major events happened around {dob} in the world"
60
+ )
61
+ chain3=LLMChain(llm=llm,prompt=third_input_prompt,verbose=True,output_key='description',memory=descr_memory)
62
+ parent_chain=SequentialChain(
63
+ chains=[chain,chain2,chain3],input_variables=['name'],output_variables=['person','dob','description'],verbose=True)
64
+
65
+
66
+
67
+ if input_text:
68
+ st.write(parent_chain({'name':input_text}))
69
+
70
+ with st.expander('Date Of Birth'):
71
+ st.info(dob_memory.buffer)
72
+
73
+ with st.expander('Person Name'):
74
+ st.info(person_memory.buffer)
75
+
76
+ with st.expander('Major Events'):
77
+ st.info(descr_memory.buffer)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ openai
2
+ langchain
3
+ streamlit
4
+ gorq