Spaces:
Sleeping
Sleeping
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. | |
Supported attributes and their operators are: | |
{related_vectors} | |
Example: | |
Input: "Show campaigns where spend is greater than 11" | |
Output: [{{"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", | |
) | |
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)) | |