kevinhug commited on
Commit
c09f094
·
1 Parent(s): 3a7bff7

example output

Browse files
Files changed (4) hide show
  1. app.py +64 -1
  2. knowledge.py +5 -2
  3. rag.py +9 -5
  4. tool.py +5 -2
app.py CHANGED
@@ -107,6 +107,11 @@ Other Links:
107
  btn_recommend.click(fn=rival_product, inputs=in_verbatim, outputs=out_product)
108
 
109
  gr.Markdown("""
 
 
 
 
 
110
  Companies in competitive industries are constantly under pressure to innovate—but often face the same challenge:
111
  ==================
112
  ### 📉 Pain points:
@@ -417,6 +422,41 @@ Customer: "No, thank you."
417
  btn_recommend.click(fn=graph, inputs=[in_verbatim, out_product], outputs=out_product)
418
 
419
  gr.Markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  Example of Customer Profile in Graph
421
  =================
422
  ![Customer Needs and Pain Points](https://i.postimg.cc/D03Sstqd/knowledge-graph1.png)
@@ -779,10 +819,14 @@ For example, Comcast reduced repeat service calls by 17% after deploying entity
779
  ],
780
  [in_verbatim]
781
  )
782
- btn_recommend = gr.Button("Recommend")
783
  btn_recommend.click(fn=rbc_product, inputs=in_verbatim, outputs=out_product)
784
 
785
  gr.Markdown("""
 
 
 
 
786
  Companies pour millions into product catalogs, marketing funnels, and user acquisition—yet many still face the same challenge:
787
  ==================
788
  ### 📉 Pain points:
@@ -857,6 +901,25 @@ For example, Comcast reduced repeat service calls by 17% after deploying entity
857
  btn_recommend = gr.Button("Mask PII")
858
  btn_recommend.click(fn=derisk, inputs=in_verbatim, outputs=out_product)
859
  gr.Markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
860
  "Is your personal banking AI trained on customer conversations—or customer identities?"
861
  ===========
862
  At RBC, generative AI is transforming personal banking—from real-time support to automated financial advice. But the same customer data powering these insights can expose the bank to regulatory violations, data breaches, and biased models—especially when names, emails, and phone numbers slip through into training or inference pipelines.
 
107
  btn_recommend.click(fn=rival_product, inputs=in_verbatim, outputs=out_product)
108
 
109
  gr.Markdown("""
110
+ Example Output
111
+ ==========
112
+ The U.S. Bank Cash+ Visa Secured Card, Capital One Quicksilver Secured Cash Rewards Credit Card, and Bank of America Customized Cash Rewards Secured Credit
113
+ Card are all options that may meet the customer's requirements.
114
+
115
  Companies in competitive industries are constantly under pressure to innovate—but often face the same challenge:
116
  ==================
117
  ### 📉 Pain points:
 
422
  btn_recommend.click(fn=graph, inputs=[in_verbatim, out_product], outputs=out_product)
423
 
424
  gr.Markdown("""
425
+ Example Output
426
+ ==============
427
+ ```
428
+ {'edges': [{'color': 'black', 'label': 'hasAccount', 'source': 1, 'target': 2},
429
+ {'color': 'black',
430
+ 'label': 'disputeCaseIsFor',
431
+ 'source': 1,
432
+ 'target': 5},
433
+ {'color': 'black', 'label': 'causedBy', 'source': 3, 'target': 4},
434
+ {'color': 'black',
435
+ 'label': 'hasChargeDispute',
436
+ 'source': 2,
437
+ 'target': 4}],
438
+ 'nodes': [{'color': 'orange',
439
+ 'id': 4,
440
+ 'label': '$329 Charge Dispute',
441
+ 'record_date': datetime.date(2023, 3, 15)},
442
+ {'color': 'orange',
443
+ 'id': 2,
444
+ 'label': 'Apple Card',
445
+ 'record_date': datetime.date(2023, 4, 5)},
446
+ {'color': 'orange',
447
+ 'id': 5,
448
+ 'label': 'GS-2025-0422-8830',
449
+ 'record_date': datetime.date(2023, 4, 5)},
450
+ {'color': 'orange',
451
+ 'id': 3,
452
+ 'label': 'TechElectronics',
453
+ 'record_date': datetime.date(2023, 3, 15)},
454
+ {'color': 'orange',
455
+ 'id': 1,
456
+ 'label': 'Michael Chen',
457
+ 'record_date': datetime.date(2023, 4, 5)}]}
458
+
459
+ ```
460
  Example of Customer Profile in Graph
461
  =================
462
  ![Customer Needs and Pain Points](https://i.postimg.cc/D03Sstqd/knowledge-graph1.png)
 
819
  ],
820
  [in_verbatim]
821
  )
822
+ btn_recommend = gr.Button("Recommend (disabled due to embedding too big for download in huggingface)", interactive=False)
823
  btn_recommend.click(fn=rbc_product, inputs=in_verbatim, outputs=out_product)
824
 
825
  gr.Markdown("""
826
+ Example Output
827
+ ===========
828
+ RBC Newcomer Mortgage
829
+
830
  Companies pour millions into product catalogs, marketing funnels, and user acquisition—yet many still face the same challenge:
831
  ==================
832
  ### 📉 Pain points:
 
901
  btn_recommend = gr.Button("Mask PII")
902
  btn_recommend.click(fn=derisk, inputs=in_verbatim, outputs=out_product)
903
  gr.Markdown("""
904
+ Example Output
905
+ =========
906
+ GUARDRAILED:
907
+ He Hua (<PERSON>) Director
908
+ hehua@chengdu.com
909
+ <PHONE_NUMBER>
910
+
911
+ Alternative Address Format:
912
+ Xiongmao Ave West Section, Jinniu District (listed in some records as 610016 postcode)
913
+
914
+
915
+ Best Viewing: Before 9:00 AM during summer hours (7:30 AM-5:00 PM)
916
+
917
+ Caretaker: <Caretaker_0>"Grandpa <PERSON>")
918
+
919
+ Additional Contacts
920
+ Charitable Donations: <PHONE_NUMBER>
921
+ Dining Reservations: <PHONE_NUMBER>
922
+
923
  "Is your personal banking AI trained on customer conversations—or customer identities?"
924
  ===========
925
  At RBC, generative AI is transforming personal banking—from real-time support to automated financial advice. But the same customer data powering these insights can expose the bank to regulatory violations, data breaches, and biased models—especially when names, emails, and phone numbers slip through into training or inference pipelines.
knowledge.py CHANGED
@@ -7,6 +7,7 @@ from pydantic import BaseModel, Field
7
 
8
  import os
9
  from datetime import date
 
10
  from groq import Groq
11
  # Initialize with API key
12
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
@@ -210,7 +211,9 @@ Representative: "Confirmed. Your next payment of $200 will process May 1st. A co
210
  Customer: "No, thank you."
211
  """
212
  graph = generate_graph(query)
213
-
 
 
214
  graph2 = generate_graph("My mortgage rate is 9%, I cannot afford it anymore, I need to refinance and I'm unemploy right now.", graph)
215
  graph2.draw()
216
-
 
7
 
8
  import os
9
  from datetime import date
10
+
11
  from groq import Groq
12
  # Initialize with API key
13
  client = Groq(api_key=os.getenv("GROQ_API_KEY"))
 
211
  Customer: "No, thank you."
212
  """
213
  graph = generate_graph(query)
214
+ from pprint import pprint
215
+ pprint(graph.model_dump())
216
+ '''
217
  graph2 = generate_graph("My mortgage rate is 9%, I cannot afford it anymore, I need to refinance and I'm unemploy right now.", graph)
218
  graph2.draw()
219
+ '''
rag.py CHANGED
@@ -2,7 +2,7 @@ import dspy
2
 
3
  import pandas as pd
4
 
5
- #lm = dspy.LM('ollama_chat/deepseek-r1', api_base='http://localhost:11434', api_key='')
6
  #lm = dspy.LM('huggingface/Qwen/Qwen2.5-Coder-32B-Instruct')
7
  #lm = dspy.LM('huggingface/meta-llama/Llama-3.2-1B')
8
  lm = dspy.LM('groq/qwen-qwq-32b')
@@ -13,21 +13,22 @@ df['content']=df['product']+"; "+df['purpose']+"; "+df['benefit']+"; "+df['fee']
13
 
14
  corpus = [row['content'] for i,row in df.iterrows()]
15
 
16
- 'huggingface/BAAI/bge-small-en-v1.5'
17
  """
18
  from sentence_transformers import SentenceTransformer
19
 
20
  # Load an extremely efficient local model for retrieval
21
- model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2", device="cpu")
22
  embedder = dspy.Embedder(model.encode)
23
  """
24
 
 
25
  import numpy as np
26
  def my_embedder(texts):
27
  return np.random.rand(len(texts), 10)
28
 
29
  embedder = dspy.Embedder(my_embedder)
30
- #embedder = dspy.Embedder('huggingface/BAAI/bge-small-en-v1.5')
31
  class RecommendProduct(dspy.Signature):
32
  """
33
  Recommend RBC financial product based on verbatim
@@ -55,4 +56,7 @@ qa = RAG(num_passages=2)
55
 
56
  def rbc_product(customer:str):
57
  response = qa(verbatim=f"Which RBC personal banking product best serve the follow customer needs, pain points: {customer}")
58
- return response.product
 
 
 
 
2
 
3
  import pandas as pd
4
 
5
+ #lm = dspy.LM('ollama_chat/llama3.2', api_base='http://localhost:11434', api_key='')
6
  #lm = dspy.LM('huggingface/Qwen/Qwen2.5-Coder-32B-Instruct')
7
  #lm = dspy.LM('huggingface/meta-llama/Llama-3.2-1B')
8
  lm = dspy.LM('groq/qwen-qwq-32b')
 
13
 
14
  corpus = [row['content'] for i,row in df.iterrows()]
15
 
16
+
17
  """
18
  from sentence_transformers import SentenceTransformer
19
 
20
  # Load an extremely efficient local model for retrieval
21
+ model = SentenceTransformer('huggingface/BAAI/bge-small-en-v1.5', device="cpu")
22
  embedder = dspy.Embedder(model.encode)
23
  """
24
 
25
+ "sentence-transformers/all-MiniLM-L6-v2"
26
  import numpy as np
27
  def my_embedder(texts):
28
  return np.random.rand(len(texts), 10)
29
 
30
  embedder = dspy.Embedder(my_embedder)
31
+ #embedder = dspy.Embedder('huggingface/BAAI/llm-embedder') #BAAI/bge-small-en-v1.5') #not working
32
  class RecommendProduct(dspy.Signature):
33
  """
34
  Recommend RBC financial product based on verbatim
 
56
 
57
  def rbc_product(customer:str):
58
  response = qa(verbatim=f"Which RBC personal banking product best serve the follow customer needs, pain points: {customer}")
59
+ return response.product
60
+
61
+ if __name__ == '__main__':
62
+ print(rbc_product(customer))
tool.py CHANGED
@@ -4,7 +4,7 @@ import dspy
4
  from dspy.predict.react import Tool
5
  from tavily import TavilyClient
6
 
7
- #lm = dspy.LM('ollama_chat/deepseek-r1', api_base='http://localhost:11434', api_key='')
8
  #lm = dspy.LM('huggingface/Qwen/Qwen2.5-Coder-32B-Instruct')
9
  #lm = dspy.LM('huggingface/meta-llama/Llama-3.2-1B')
10
  lm = dspy.LM('groq/qwen-qwq-32b')
@@ -24,4 +24,7 @@ customer="Low APR and great customer service. I would highly recommend if you’
24
 
25
  def rival_product(customer:str):
26
  prediction = agent(verbatim=f"Which banking product name best serve this customer needs: {customer}")
27
- return prediction.product
 
 
 
 
4
  from dspy.predict.react import Tool
5
  from tavily import TavilyClient
6
 
7
+ #lm = dspy.LM('ollama_chat/llama3.2', api_base='http://localhost:11434', api_key='')
8
  #lm = dspy.LM('huggingface/Qwen/Qwen2.5-Coder-32B-Instruct')
9
  #lm = dspy.LM('huggingface/meta-llama/Llama-3.2-1B')
10
  lm = dspy.LM('groq/qwen-qwq-32b')
 
24
 
25
  def rival_product(customer:str):
26
  prediction = agent(verbatim=f"Which banking product name best serve this customer needs: {customer}")
27
+ return prediction.product
28
+
29
+ if __name__ == '__main__':
30
+ print(rival_product(customer))