camparchimedes commited on
Commit
e6c7289
Β·
verified Β·
1 Parent(s): a99b012

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -21
app.py CHANGED
@@ -1,7 +1,7 @@
1
 
2
- # ===========================================
3
- # "the-very-latest"-----app.py ✍🏽 🎬
4
- # ===========================================
5
 
6
  import asyncio
7
  import concurrent.futures
@@ -18,6 +18,10 @@ from langchain_openai import OpenAI
18
  from tiktoken import encoding_for_model
19
  from langchain.chains import LLMChain, APIChain
20
  from langchain_core.prompts import PromptTemplate
 
 
 
 
21
  from langchain.memory.buffer import ConversationBufferMemory
22
  from langchain.memory import ConversationTokenBufferMemory
23
  from langchain.memory import ConversationSummaryMemory
@@ -113,34 +117,40 @@ def setup_multiple_chains():
113
  async def handle_message(message: cl.Message):
114
  user_message = message.content
115
  llm_chain = cl.user_session.get("llm_chain")
116
- api_chain = cl.user_session.get("api_chain")
117
 
 
118
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
119
- #endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
120
 
121
  if re.search(booking_pattern, user_message):
122
  bestillingskode = re.search(booking_pattern, user_message).group(0)
123
- headers = {
124
- "Authorization": auth_token,
125
- #"Content-Type": "application/json"
126
- }
127
- question = f"Retrieve booking information associated with a booking ID"
128
 
129
- # --------------------------------AD VAL.III--------------------------------
 
 
 
 
 
 
 
 
 
 
130
 
131
- response = await api_chain.acall(
132
- {
133
- "headers": headers,
134
  "body": {
135
- "booking_id": bestillingskode,
136
- },
137
- "question": question,
138
- },
139
- callbacks=[cl.AsyncLangchainCallbackHandler()]
 
 
140
  )
 
141
 
142
- # --------------------------------------------------------------------------
143
-
144
  else:
145
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
146
 
@@ -148,3 +158,4 @@ async def handle_message(message: cl.Message):
148
  await cl.Message(response.get(response_key, "")).send()
149
  return message.content
150
 
 
 
1
 
2
+ # ===================================================
3
+ # "the-very-latest-&-did-not-GET-it"-----app.py ✍🏽 🎬
4
+ # ===================================================
5
 
6
  import asyncio
7
  import concurrent.futures
 
18
  from tiktoken import encoding_for_model
19
  from langchain.chains import LLMChain, APIChain
20
  from langchain_core.prompts import PromptTemplate
21
+
22
+ from langchain_community.tools.requests.tool import RequestsPostTool
23
+ from langchain.utilities.requests import TextRequestsWrapper
24
+
25
  from langchain.memory.buffer import ConversationBufferMemory
26
  from langchain.memory import ConversationTokenBufferMemory
27
  from langchain.memory import ConversationSummaryMemory
 
117
  async def handle_message(message: cl.Message):
118
  user_message = message.content
119
  llm_chain = cl.user_session.get("llm_chain")
120
+ #api_chain = cl.user_session.get("api_chain")
121
 
122
+ # --------------------------------AD VAL.II.7--------------------------------
123
  booking_pattern = r'\b[A-Z]{6}\d{6}\b'
124
+ endpoint_url = "https://aivisions.no/data/daysoff/api/v1/booking/"
125
 
126
  if re.search(booking_pattern, user_message):
127
  bestillingskode = re.search(booking_pattern, user_message).group(0)
 
 
 
 
 
128
 
129
+ requests_wrapper = TextRequestsWrapper(
130
+ headers={
131
+ "Authorization": auth_token,
132
+ "Content-Type": "application/json"
133
+ }
134
+ )
135
+
136
+ post_tool = RequestsPostTool(
137
+ requests_wrapper=requests_wrapper,
138
+ allow_dangerous_requests=True
139
+ )
140
 
141
+ post_data = {
142
+ "url": endpoint_url,
 
143
  "body": {
144
+ "booking_id": bestillingskode
145
+ }
146
+ }
147
+
148
+ response = await post_tool.acall(
149
+ json.dumps(post_data),
150
+ callbacks=[cl.AsyncLangchainCallbackHandler()]
151
  )
152
+ # --------------------------------AD VAL.@End--------------------------------
153
 
 
 
154
  else:
155
  response = await llm_chain.acall(user_message, callbacks=[cl.AsyncLangchainCallbackHandler()])
156
 
 
158
  await cl.Message(response.get(response_key, "")).send()
159
  return message.content
160
 
161
+