File size: 1,437 Bytes
18c7cc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
# Default
import os
from groq import Groq
import traceback

client = Groq(
    # This is the default and can be omitted
    api_key=os.environ.get("GROQ_API_KEY"),
)

def chat_with_groq(user_input, additional_info=None):
    
    try:

        template_prompt = f"""
        
        You are a professional email writer who specialises in writing cold email.
        Generate a cold email to {user_input['recipient_name']} based on the following information:
        
        Industry: {user_input['industry']}
        Tone: {user_input['tone']}
        Context: {user_input['context']}
        Senders Name: {user_input['name']}
        Designation: {user_input['designation']}

        Incorporate all information and write a compelling email.

        """

        # test purposes:
        # return template_prompt
        chat_completion = client.chat.completions.create(
            messages=[
                {
                    "role": "system",
                    "content": "You are an expert email writer specializing in cold emails.",
                },
                {
                    "role": "user",
                    "content": template_prompt,
                }
            ],
            model="mixtral-8x7b-32768",
        )

        generated_email = chat_completion.choices[0].message.content
        return generated_email


    except Exception as err:
        traceback.print_exc()
        print(err)