Spaces:
Runtime error
Runtime error
Download utils.py from bobrod20/rtm-generator: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/spaces/bobrod20/rtm-generator/resolve/main/utils.py
- Command line
-
hf download hf://spaces/bobrod20/rtm-generator/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/bobrod20/rtm-generator/resolve/main/utils.py
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 | |
| ) |