Skip to content

Commit

Permalink
add first application post generator
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabenevenuta committed Nov 23, 2023
1 parent 90f0cbc commit 8f8bce0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
openapi_key.txt
openapi_key.txt

*.pyc
22 changes: 22 additions & 0 deletions applications/dataroots_recuitment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import streamlit as st
import langchain_helper as lch
from dotenv import load_dotenv
import os

load_dotenv("openapi_key.txt")
openai_api_key = os.getenv('OPENAI_API_KEY')

st.title(":iphone: Dataroots Posts Generator")

# Sidebar select box
st.sidebar.title('Customize your post')
social_network = st.sidebar.selectbox('Select Social Network:', ['Instagram', 'LinkedIn'])
position = st.sidebar.selectbox('Select Position:', ['Machine Learning Engineer', 'Data Engineer', 'Data Strategy'])
tone = st.sidebar.selectbox('Select Tone:', ['Formal', 'Informal'])
max_words = st.sidebar.slider('Max Number of Words', min_value=100, max_value=1000, value=200)
temperature = st.sidebar.slider('Model temperature', min_value=0.0, max_value=1.0, value=0.5, step=0.01)

# Generate button
if st.sidebar.button('Generate'):
response = lch.generate_post_dataroots(social_network, position, tone, max_words, temperature, openai_api_key)
st.text(response['generated_post'])
40 changes: 40 additions & 0 deletions applications/langchain_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import streamlit as st
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain



def generate_post_dataroots(social_network, position, tone, max_words, temperature, openai_api_key):
llm = OpenAI(temperature=temperature, openai_api_key=openai_api_key)

my_prompt = PromptTemplate(
input_variables = ["social_network", "position", "tone", "max_words"],
input_types={
"social_network": str,
"position": str,
"tone": str,
"max_words": int
},
template = """
You are Dataroots assistant and you are here to help HR create new posts on {social_network} to recruite new people.
The post should be about looking for a {position}.
The tone must be {tone}.
The max number of words for the post should be {max_words}.
Be as captivating as possible and use emojis to convey the message.
"""
)

recruitment_chain = LLMChain(llm=llm, prompt=my_prompt, output_key="generated_post")

response = recruitment_chain({
"social_network": social_network,
"position": position,
"tone": tone,
"max_words": max_words
})

return response

if __name__ == "__main__":
print(generate_post_dataroots("Instagram", "Machine Learning Engineer", "informal", 200, 0))

0 comments on commit 8f8bce0

Please sign in to comment.