Kate Forsberg commited on
Commit
67a06c2
·
1 Parent(s): f787fa1
Files changed (3) hide show
  1. app.py +32 -27
  2. feclx5wyaca.json +1 -0
  3. mjcgsn7aj7.json +1 -0
app.py CHANGED
@@ -10,8 +10,18 @@ from griptape.tools import Calculator
10
  from griptape.rules import Rule
11
  import time
12
 
 
 
 
 
 
13
  repo_id = "kateforsberg/gradio-test"
14
  api = HfApi()
 
 
 
 
 
15
 
16
  def user(user_message, history):
17
  history.append([user_message, None])
@@ -27,40 +37,35 @@ def bot(history):
27
 
28
  yield history
29
 
30
- agent = Agent(
31
- conversation_memory=ConversationMemory(
32
- driver=LocalConversationMemoryDriver(
33
- file_path="conversation_memory.json"
34
- )),
35
- tools=[Calculator()],
36
- rules=[
37
- Rule(
38
- value = "You are an intelligent agent tasked with answering questions."
39
- ),
40
- Rule(
41
- value = "All of your responses are less than 5 sentences."
42
- ) ]
43
- )
 
44
 
45
- workflow = Workflow()
46
- start_task = PromptTask("I will provide you two dog breeds to compare", id="START")
47
- end_task = PromptTask("How are the dog breeds different", id="END")
48
- workflow.add_task(start_task)
49
- workflow.add_task(end_task)
50
- dog_task = PromptTask("Poodle and a Labrador", id="DOG")
51
- workflow.insert_tasks(start_task,[dog_task],end_task)
52
 
53
- def use_workflow(message:str, history) -> Any:
54
- response = workflow.run()
55
- return response.output.value
56
 
57
- def send_message(message:str, history,) -> Any:
 
 
 
58
  response = agent.run(message)
59
  return response.output.value
60
 
61
  demo = gr.ChatInterface(
62
  fn=send_message,
63
  )
64
- demo.launch(
65
- auth=("griptape","griptaper"))
 
66
 
 
10
  from griptape.rules import Rule
11
  import time
12
 
13
+
14
+ # Idea - what if we could make an api call to huggingface and add secret .env variables for each person
15
+ # In this case, it should run no matter what
16
+ # Can add a .env that has session ID and use Redis for conversation memory
17
+
18
  repo_id = "kateforsberg/gradio-test"
19
  api = HfApi()
20
+ #api.add_space_secret(repo_id=repo_id, key='OPENAI_API_KEY', value='sk-1234')
21
+ # Could this create a variable that's unique to each session?
22
+ #api.add_space_variable(repo_id=repo_id, key='SESSION_ID', value=str(uuid()))
23
+
24
+ sessions = {}
25
 
26
  def user(user_message, history):
27
  history.append([user_message, None])
 
37
 
38
  yield history
39
 
40
+ def build_agent(session_id:str):
41
+ return Agent(
42
+ conversation_memory=ConversationMemory(
43
+ driver=LocalConversationMemoryDriver(
44
+ file_path=f'{session_id}.json'
45
+ )),
46
+ tools=[Calculator()],
47
+ rules=[
48
+ Rule(
49
+ value = "You are an intelligent agent tasked with answering questions."
50
+ ),
51
+ Rule(
52
+ value = "All of your responses are less than 5 sentences."
53
+ ) ]
54
+ )
55
 
 
 
 
 
 
 
 
56
 
 
 
 
57
 
58
+ def send_message(message:str, history, request:gr.Request) -> Any:
59
+ if request:
60
+ session_hash = request.session_hash
61
+ agent = build_agent(session_hash)
62
  response = agent.run(message)
63
  return response.output.value
64
 
65
  demo = gr.ChatInterface(
66
  fn=send_message,
67
  )
68
+ demo.launch(share=True)
69
+
70
+ #auth=("griptape","griptaper")
71
 
feclx5wyaca.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"type": "ConversationMemory", "runs": [{"type": "Run", "id": "68795eba02cc4f2dafb58e2ae39b50a6", "input": {"type": "TextArtifact", "id": "ea12e13253e442eeb788a68e5ab2180c", "reference": null, "meta": {}, "name": "ea12e13253e442eeb788a68e5ab2180c", "value": "what are you"}, "output": {"type": "TextArtifact", "id": "e97d2f0bfe21482e83f8f8c73c999242", "reference": null, "meta": {}, "name": "e97d2f0bfe21482e83f8f8c73c999242", "value": "I am an intelligent agent designed to assist with answering questions and performing tasks such as calculations. How can I help you today?"}}, {"type": "Run", "id": "631c4709041841d5bd6e6f84793f8833", "input": {"type": "TextArtifact", "id": "7ddd118d20604c4d85050ca42e6a6d67", "reference": null, "meta": {}, "name": "7ddd118d20604c4d85050ca42e6a6d67", "value": "what was the last thing i said"}, "output": {"type": "TextArtifact", "id": "b73f2fc05c1c4df9a48a3ce6b360f2ab", "reference": null, "meta": {}, "name": "b73f2fc05c1c4df9a48a3ce6b360f2ab", "value": "You asked, \"what are you?\""}}, {"type": "Run", "id": "f317d2f9f4f742cfb3ecf1458d9107cb", "input": {"type": "TextArtifact", "id": "a8868bf90080409b9cb74b590a5f033e", "reference": null, "meta": {}, "name": "a8868bf90080409b9cb74b590a5f033e", "value": "ok lit"}, "output": {"type": "TextArtifact", "id": "34960ba434fb4a488d5d99ea1e8098cc", "reference": null, "meta": {}, "name": "34960ba434fb4a488d5d99ea1e8098cc", "value": "Great! How can I assist you further?"}}], "max_runs": null}
mjcgsn7aj7.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"type": "ConversationMemory", "runs": [{"type": "Run", "id": "b20024cc07d44cfca53911240a680f37", "input": {"type": "TextArtifact", "id": "9c9f57c1527542a69627a5be494dcb40", "reference": null, "meta": {}, "name": "9c9f57c1527542a69627a5be494dcb40", "value": "hi there"}, "output": {"type": "TextArtifact", "id": "ca15b8187e684e8597e27ce0eb9d4d60", "reference": null, "meta": {}, "name": "ca15b8187e684e8597e27ce0eb9d4d60", "value": "Hello! How can I assist you today?"}}, {"type": "Run", "id": "30adf7f962b24a619a3009684b069de2", "input": {"type": "TextArtifact", "id": "10fab83b16a54cbb9d5456d8bb32b3f3", "reference": null, "meta": {}, "name": "10fab83b16a54cbb9d5456d8bb32b3f3", "value": "what was the last thing i said"}, "output": {"type": "TextArtifact", "id": "349771f62bff442184c8825b42dc6d9c", "reference": null, "meta": {}, "name": "349771f62bff442184c8825b42dc6d9c", "value": "You said, \"hi there.\" How can I help you further?"}}, {"type": "Run", "id": "9da15db3d45547e8a5bed2ed2a904afc", "input": {"type": "TextArtifact", "id": "9bbe11989f7a40f7a9146b10c42fd857", "reference": null, "meta": {}, "name": "9bbe11989f7a40f7a9146b10c42fd857", "value": "what was the last thing i said"}, "output": {"type": "TextArtifact", "id": "cafc351aa90e4fac8295c1109154dcec", "reference": null, "meta": {}, "name": "cafc351aa90e4fac8295c1109154dcec", "value": "You said, \"what was the last thing i said.\" How can I assist you further?"}}], "max_runs": null}