File size: 1,790 Bytes
7b240d9
5518038
 
 
7b240d9
5518038
 
7b240d9
5518038
 
 
 
 
 
 
 
 
afabc6a
5518038
 
 
 
 
afabc6a
 
 
 
 
5518038
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afabc6a
 
5518038
 
 
7b240d9
 
 
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
57
58
59
import os
from groq import Groq

client = Groq(
    api_key=os.getenv('GROQ_API_KEY'),
)

def generate_chat_completion(USER_INPUT, related_vectors):

    SYSTEM_PROMPT = f'''
    You are a system that converts natural language queries into a structured filter schema.
    The filter schema consists of a list of conditions, each represented as:
    {{
        "attribute": "<attribute_name>",
        "op": "<operator>",
        "value": "<value>"
    }}
    There can be any number of conditions. You have to list them all. But no attributes outside the natural language context

    Supported attributes and their operators are:
    {related_vectors}

    Example:
    Input: "Show campaigns with no sales but spend is greater than 11"
    Output: [
        {{"attribute": "sales", "op": "=", "value": 0}},
        {{"attribute": "spend", "op": ">", "value": 11}}
    ]

    Input: "Find ads with clicks less than 100 and impressions greater than 500"
    Output: [
        {{"attribute": "clicks", "op": "<", "value": 100}},
        {{"attribute": "impressions", "op": ">", "value": 500}}
    ]

    STRICLY PROVIDE IN THE ABOVE JSON FORMAT WITHOUT ANY METADATA

    '''
    
    chat_completion = client.chat.completions.create(
        messages=[
            {
                "role": "system",
                "content": SYSTEM_PROMPT,
            },
            {
                "role": "user",
                "content": USER_INPUT,
            },
        ],
        # model="llama3-8b-8192",
        model="gemma2-9b-it"
    )
    return chat_completion.choices[0].message.content

#Test input
# USER_INPUT = "Show campaigns where spend is greater than 11 and labels include holiday and with impressions less than 500"
# print(generate_chat_completion(SYSTEM_PROMPT, USER_INPUT))