OmkarG commited on
Commit
a51ac58
·
1 Parent(s): 3f7221a

commented apppy

Browse files
Files changed (3) hide show
  1. LLM_test.py +2 -4
  2. app.py +32 -32
  3. 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 RAG_test import fetch
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, SYSTEM_PROMPT, USER_INPUT, related_vectors):
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 RAG_test 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,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, SYSTEM_PROMPT, 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 sentence"), # Input field
59
- outputs=gr.Textbox(label="Generated Completion"), # Output field
60
- title="Chat Completion Generator", # Title of the app
61
- description="This app generates chat completions based on a user-provided input sentence."
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