Spaces:
Runtime error

rtm-generator / utils.py
bobrod20's picture
Rename utils_refactored.py to utils.py
8c78c03 verified
Raw History Blame Contribute Delete
1.83 kB
import openai
import requests
from prompts import rtm_prompt_template, prospecting_prompt_template
client = openai.OpenAI()
def generate_rtm(company, website):
prompt = rtm_prompt_template.format(company=company, website=website)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content.strip()
def generate_prospecting_message(linkedin_url, context, rtm_text, workspace=None, custom_title=None, ghostwriter_url=None, is_followup=False):
name = "[First Name]"
if "linkedin.com" in linkedin_url:
try:
resp = requests.get(linkedin_url, timeout=10)
name = resp.text.split("firstName")[1].split('"')[1]
except Exception:
pass
ghost_note = f"You're writing on behalf of someone else: {ghostwriter_url}" if ghostwriter_url else ""
title_hint = f"Their known title is: {custom_title}." if custom_title else ""
message_type = "follow-up" if is_followup else "first-touch"
prompt = prospecting_prompt_template.format(
type=message_type,
recipient_name=name,
title_hint=title_hint,
ghost_note=ghost_note,
context=context,
rtm_text=rtm_text
)
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content.strip()
def generate_followup_message(linkedin_url, context, rtm_text, workspace=None, custom_title=None, ghostwriter_url=None):
return generate_prospecting_message(
linkedin_url,
context,
rtm_text,
workspace=workspace,
custom_title=custom_title,
ghostwriter_url=ghostwriter_url,
is_followup=True
)