geqintan commited on
Commit
63d40fb
·
1 Parent(s): aa3e29b
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. redis_service.py +50 -1
  3. requirements.txt +1 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
redis_service.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  import asyncio
3
  import redis.asyncio as redis
4
  from dotenv import load_dotenv
@@ -75,6 +75,55 @@ async def redis_subscriber(redis_client, channel_name):
75
  # Extract necessary info from data_dict for sending reply
76
  msg_id = data_dict.get('msg_id')
77
  content = data_dict.get('content') # This should be the dictionary like {"text": "..."}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  # Correctly extract msg_type from the original_msg_type field
79
  msg_type = data_dict.get('original_msg_type')
80
 
 
1
+ import os, requests
2
  import asyncio
3
  import redis.asyncio as redis
4
  from dotenv import load_dotenv
 
75
  # Extract necessary info from data_dict for sending reply
76
  msg_id = data_dict.get('msg_id')
77
  content = data_dict.get('content') # This should be the dictionary like {"text": "..."}
78
+ print('content["text"]',content["text"])
79
+
80
+
81
+ response = requests.get("https://tanbushi-adk-teams.hf.space/apps/ai_quant/users/tanbushi/sessions/ai_quant_tanbushi_session")
82
+ if (response.status_code != 200):
83
+ print("Failed to get session")
84
+ response=requests.post("https://tanbushi-adk-teams.hf.space/apps/ai_quant/users/tanbushi/sessions/ai_quant_tanbushi_session")
85
+ if (response.status_code==200):
86
+ data = {
87
+ "app_name": "ai_quant",
88
+ "user_id": "user",
89
+ "session_id": "232d4228-d3a2-41ee-99eb-3db5b307260e",
90
+ "new_message": {
91
+ "parts": [
92
+ {
93
+ "text": content["text"]
94
+ }
95
+ ],
96
+ "role": "user"
97
+ },
98
+ "streaming": False
99
+ }
100
+ response1 = requests.post("https://tanbushi-adk-teams.hf.space/run", json=data)
101
+ ret_text = response1.json()[0]['content']['parts'][0]['text']
102
+ print(ret_text)
103
+ else:
104
+ print("Successfully get session")
105
+ data = {
106
+ "app_name": "ai_quant",
107
+ "user_id": "tanbushi",
108
+ "session_id": "ai_quant_tanbushi_session",
109
+ "new_message": {
110
+ "parts": [
111
+ {
112
+ "text": content["text"]
113
+ }
114
+ ],
115
+ "role": "user"
116
+ },
117
+ "streaming": False
118
+ }
119
+ response1 = requests.post("https://tanbushi-adk-teams.hf.space/run", json=data)
120
+ ret_text = response1.json()[0]['content']['parts'][0]['text']
121
+ print(ret_text)
122
+
123
+
124
+
125
+
126
+ content = {"text": ret_text}
127
  # Correctly extract msg_type from the original_msg_type field
128
  msg_type = data_dict.get('original_msg_type')
129
 
requirements.txt CHANGED
@@ -4,3 +4,4 @@ redis
4
  python-dotenv
5
  httpx
6
  supabase
 
 
4
  python-dotenv
5
  httpx
6
  supabase
7
+ requests