Spaces:
Sleeping
Sleeping
commented apppy
Browse files- LLM_test.py +2 -4
- app.py +32 -32
- RAG_test.py → retrieval_helper.py +0 -0
LLM_test.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import groq, os
|
2 |
from groq import Groq
|
3 |
-
from
|
4 |
|
5 |
client = Groq(
|
6 |
api_key="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", # This is the default and can be omitted
|
@@ -16,11 +16,9 @@ query = "Show campaigns where spend is greater than 11 and labels include holida
|
|
16 |
top_documents = fetch(query)
|
17 |
|
18 |
|
19 |
-
|
20 |
-
|
21 |
USER_INPUT = "Show campaigns where spend is greater than 11 and labels include holiday and with impressions less than 500"
|
22 |
|
23 |
-
def generate_chat_completion(client,
|
24 |
|
25 |
|
26 |
SYSTEM_PROMPT = f'''
|
|
|
1 |
import groq, os
|
2 |
from groq import Groq
|
3 |
+
from retrieval_helper import fetch
|
4 |
|
5 |
client = Groq(
|
6 |
api_key="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", # This is the default and can be omitted
|
|
|
16 |
top_documents = fetch(query)
|
17 |
|
18 |
|
|
|
|
|
19 |
USER_INPUT = "Show campaigns where spend is greater than 11 and labels include holiday and with impressions less than 500"
|
20 |
|
21 |
+
def generate_chat_completion(client, USER_INPUT, related_vectors):
|
22 |
|
23 |
|
24 |
SYSTEM_PROMPT = f'''
|
app.py
CHANGED
@@ -1,46 +1,46 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from LLM_test import generate_chat_completion
|
4 |
-
from
|
5 |
from groq import Groq
|
6 |
|
7 |
client = Groq(
|
8 |
api_key="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", # This is the default and can be omitted
|
9 |
)
|
10 |
|
11 |
-
related_vectors = '''
|
12 |
-
attribute: spend, operators_supported: [">", "<", ">=", "<=", "=", "!="], value_type: "Number"
|
13 |
-
attribute: clicks, operators_supported: [">", "<", ">=", "<=", "=", "!="], value_type: "Integer"
|
14 |
-
attribute: impressions, operators_supported: [">", "<", ">=", "<=", "=", "!="], value_type: "Integer"
|
15 |
-
'''
|
16 |
|
17 |
|
18 |
-
SYSTEM_PROMPT = f'''
|
19 |
-
You are a system that converts natural language queries into a structured filter schema.
|
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 |
# Define the Gradio interface
|
46 |
def generate_chat_completion_interface(USER_INPUT):
|
@@ -48,17 +48,17 @@ def generate_chat_completion_interface(USER_INPUT):
|
|
48 |
top_documents = fetch(USER_INPUT)
|
49 |
related_vectors = "\n".join(top_documents)
|
50 |
|
51 |
-
result = generate_chat_completion(client,
|
52 |
|
53 |
return result
|
54 |
|
55 |
# Set up the Gradio app interface
|
56 |
iface = gr.Interface(
|
57 |
fn=generate_chat_completion_interface, # Function to run on input
|
58 |
-
inputs=gr.Textbox(label="Enter your
|
59 |
-
outputs=gr.Textbox(label="Generated
|
60 |
-
title="
|
61 |
-
description="
|
62 |
)
|
63 |
|
64 |
# Launch the interface
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from LLM_test import generate_chat_completion
|
4 |
+
from retrieval_helper import fetch
|
5 |
from groq import Groq
|
6 |
|
7 |
client = Groq(
|
8 |
api_key="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", # This is the default and can be omitted
|
9 |
)
|
10 |
|
11 |
+
# related_vectors = '''
|
12 |
+
# attribute: spend, operators_supported: [">", "<", ">=", "<=", "=", "!="], value_type: "Number"
|
13 |
+
# attribute: clicks, operators_supported: [">", "<", ">=", "<=", "=", "!="], value_type: "Integer"
|
14 |
+
# attribute: impressions, operators_supported: [">", "<", ">=", "<=", "=", "!="], value_type: "Integer"
|
15 |
+
# '''
|
16 |
|
17 |
|
18 |
+
# SYSTEM_PROMPT = f'''
|
19 |
+
# You are a system that converts natural language queries into a structured filter schema.
|
20 |
+
# The filter schema consists of a list of conditions, each represented as:
|
21 |
+
# {{
|
22 |
+
# "attribute": "<attribute_name>",
|
23 |
+
# "op": "<operator>",
|
24 |
+
# "value": "<value>"
|
25 |
+
# }}
|
26 |
+
# There can be any number of conditions. You have to list them all.
|
27 |
|
28 |
+
# Supported attributes and their operators are:
|
29 |
+
# {related_vectors}
|
30 |
|
31 |
+
# Example:
|
32 |
+
# Input: "Show campaigns where spend is greater than 11"
|
33 |
+
# Output: [{{"attribute": "spend", "op": ">", "value": 11}}]
|
34 |
|
35 |
+
# Input: "Find ads with clicks less than 100 and impressions greater than 500"
|
36 |
+
# Output: [
|
37 |
+
# {{"attribute": "clicks", "op": "<", "value": 100}},
|
38 |
+
# {{"attribute": "impressions", "op": ">", "value": 500}}
|
39 |
+
# ]
|
40 |
|
41 |
+
# STRICLY PROVIDE IN THE ABOVE JSON FORMAT WITHOUT ANY METADATA
|
42 |
|
43 |
+
# '''
|
44 |
|
45 |
# Define the Gradio interface
|
46 |
def generate_chat_completion_interface(USER_INPUT):
|
|
|
48 |
top_documents = fetch(USER_INPUT)
|
49 |
related_vectors = "\n".join(top_documents)
|
50 |
|
51 |
+
result = generate_chat_completion(client, USER_INPUT, related_vectors)
|
52 |
|
53 |
return result
|
54 |
|
55 |
# Set up the Gradio app interface
|
56 |
iface = gr.Interface(
|
57 |
fn=generate_chat_completion_interface, # Function to run on input
|
58 |
+
inputs=gr.Textbox(label="Enter your query"), # Input field
|
59 |
+
outputs=gr.Textbox(label="Generated JSON"), # Output field
|
60 |
+
title="RAG based search", # Title of the app
|
61 |
+
description="Provide your natural language searhc query"
|
62 |
)
|
63 |
|
64 |
# Launch the interface
|
RAG_test.py → retrieval_helper.py
RENAMED
File without changes
|