RAG_based_search / groq_helper.py
OmkarG's picture
adjusted prompt to handle no case scenarios
afabc6a
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))