Spaces:
Runtime error
Runtime error
File size: 1,832 Bytes
32f6e38 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 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
) |