Broomva commited on
Commit
eea0255
·
1 Parent(s): e355acf
Files changed (2) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +100 -98
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
app.py CHANGED
@@ -21,91 +21,91 @@ embeddings = OpenAIEmbeddings()
21
  vector_store = FAISS.load_local("docs.faiss", embeddings)
22
 
23
 
24
- @cl.oauth_callback
25
- def oauth_callback(
26
- provider_id: str,
27
- token: str,
28
- raw_user_data: Dict[str, str],
29
- default_app_user: cl.AppUser,
30
- ) -> Optional[cl.AppUser]:
31
- # set AppUser tags as regular_user
32
- match default_app_user.username:
33
- case "Broomva":
34
- default_app_user.tags = ["admin_user"]
35
- default_app_user.role = "ADMIN"
36
- case _:
37
- default_app_user.tags = ["regular_user"]
38
- default_app_user.role = "USER"
39
- print(default_app_user)
40
- return default_app_user
41
-
42
-
43
- @cl.header_auth_callback
44
- def header_auth_callback(headers) -> Optional[cl.AppUser]:
45
- # Verify the signature of a token in the header (ex: jwt token)
46
- # or check that the value is matching a row from your database
47
- print(headers)
48
- if (
49
- headers.get("cookie")
50
- == "ajs_user_id=5011e946-0d0d-5bd4-a293-65742db98d3d; ajs_anonymous_id=67d2569d-3f50-48f3-beaf-b756286276d9"
51
- ):
52
- return cl.AppUser(username="Broomva", role="ADMIN", provider="header")
53
- else:
54
- return None
55
-
56
-
57
- @cl.password_auth_callback
58
- def auth_callback(
59
- username: str = "guest", password: str = "guest"
60
- ) -> Optional[cl.AppUser]:
61
- # Fetch the user matching username from your database
62
- # and compare the hashed password with the value stored in the database
63
- import hashlib
64
-
65
- # Create a new sha256 hash object
66
- hash_object = hashlib.sha256()
67
-
68
- # Hash the password
69
- hash_object.update(password.encode())
70
-
71
- # Get the hexadecimal representation of the hash
72
- hashed_password = hash_object.hexdigest()
73
-
74
- if (username, hashed_password) == (
75
- "broomva",
76
- "b68cacbadaee450b8a8ce2dd44842f1de03ee9993ad97b5e99dea64ef93960ba",
77
- ):
78
- return cl.AppUser(username="Broomva", role="ADMIN", provider="credentials")
79
- elif (username, password) == ("guest", "guest"):
80
- return cl.AppUser(username="Guest", role="USER", provider="credentials")
81
- else:
82
- return None
83
-
84
-
85
- @cl.set_chat_profiles
86
- async def chat_profile(current_user: cl.AppUser):
87
- if "ADMIN" not in current_user.role:
88
- # Default to 3.5 when not admin
89
- return [
90
- cl.ChatProfile(
91
- name="Broomva Book Agent",
92
- markdown_description="The underlying LLM model is **GPT-3.5**.",
93
- # icon="https://picsum.photos/200",
94
- ),
95
- ]
96
-
97
- return [
98
- cl.ChatProfile(
99
- name="Broomva Book Agent Lite",
100
- markdown_description="The underlying LLM model is **GPT-3.5**.",
101
- # icon="https://picsum.photos/200",
102
- ),
103
- cl.ChatProfile(
104
- name="Broomva Book Agent Turbo",
105
- markdown_description="The underlying LLM model is **GPT-4 Turbo**.",
106
- # icon="https://picsum.photos/250",
107
- ),
108
- ]
109
 
110
 
111
  @cl.on_settings_update
@@ -115,6 +115,7 @@ async def setup_agent(settings):
115
 
116
  @cl.on_chat_start
117
  async def init():
 
118
  settings = await cl.ChatSettings(
119
  [
120
  Select(
@@ -148,12 +149,12 @@ async def init():
148
  ]
149
  ).send()
150
 
151
- chat_profile = cl.user_session.get("chat_profile")
152
 
153
- if chat_profile == "Broomva Book Agent Lite":
154
- settings["model"] = "gpt-3.5-turbo"
155
- elif chat_profile == "Broomva Book Agent Turbo":
156
- settings["model"] = "gpt-4-1106-preview"
157
 
158
  chain = RetrievalQAWithSourcesChain.from_chain_type(
159
  ChatOpenAI(
@@ -178,15 +179,16 @@ async def main(message):
178
  )
179
  cb.answer_reached = True
180
 
181
- res = await chain.acall(message.content, callbacks=[cb])
182
 
183
- if cb.has_streamed_final_answer:
184
- await cb.final_stream.update()
185
- else:
186
- answer = res["answer"]
187
- await cl.Message(
188
- content=answer,
189
- ).send()
 
190
 
191
 
192
  # # Instantiate the LLM
 
21
  vector_store = FAISS.load_local("docs.faiss", embeddings)
22
 
23
 
24
+ # @cl.oauth_callback
25
+ # def oauth_callback(
26
+ # provider_id: str,
27
+ # token: str,
28
+ # raw_user_data: Dict[str, str],
29
+ # default_app_user: cl.AppUser,
30
+ # ) -> Optional[cl.AppUser]:
31
+ # # set AppUser tags as regular_user
32
+ # match default_app_user.username:
33
+ # case "Broomva":
34
+ # default_app_user.tags = ["admin_user"]
35
+ # default_app_user.role = "ADMIN"
36
+ # case _:
37
+ # default_app_user.tags = ["regular_user"]
38
+ # default_app_user.role = "USER"
39
+ # print(default_app_user)
40
+ # return default_app_user
41
+
42
+
43
+ # @cl.header_auth_callback
44
+ # def header_auth_callback(headers) -> Optional[cl.AppUser]:
45
+ # # Verify the signature of a token in the header (ex: jwt token)
46
+ # # or check that the value is matching a row from your database
47
+ # print(headers)
48
+ # if (
49
+ # headers.get("cookie")
50
+ # == "ajs_user_id=5011e946-0d0d-5bd4-a293-65742db98d3d; ajs_anonymous_id=67d2569d-3f50-48f3-beaf-b756286276d9"
51
+ # ):
52
+ # return cl.AppUser(username="Broomva", role="ADMIN", provider="header")
53
+ # else:
54
+ # return None
55
+
56
+
57
+ # @cl.password_auth_callback
58
+ # def auth_callback(
59
+ # username: str = "guest", password: str = "guest"
60
+ # ) -> Optional[cl.AppUser]:
61
+ # # Fetch the user matching username from your database
62
+ # # and compare the hashed password with the value stored in the database
63
+ # import hashlib
64
+
65
+ # # Create a new sha256 hash object
66
+ # hash_object = hashlib.sha256()
67
+
68
+ # # Hash the password
69
+ # hash_object.update(password.encode())
70
+
71
+ # # Get the hexadecimal representation of the hash
72
+ # hashed_password = hash_object.hexdigest()
73
+
74
+ # if (username, hashed_password) == (
75
+ # "broomva",
76
+ # "b68cacbadaee450b8a8ce2dd44842f1de03ee9993ad97b5e99dea64ef93960ba",
77
+ # ):
78
+ # return cl.AppUser(username="Broomva", role="ADMIN", provider="credentials")
79
+ # elif (username, password) == ("guest", "guest"):
80
+ # return cl.AppUser(username="Guest", role="USER", provider="credentials")
81
+ # else:
82
+ # return None
83
+
84
+
85
+ # @cl.set_chat_profiles
86
+ # async def chat_profile(current_user: cl.AppUser):
87
+ # if "ADMIN" not in current_user.role:
88
+ # # Default to 3.5 when not admin
89
+ # return [
90
+ # cl.ChatProfile(
91
+ # name="Broomva Book Agent",
92
+ # markdown_description="The underlying LLM model is **GPT-3.5**.",
93
+ # # icon="https://picsum.photos/200",
94
+ # ),
95
+ # ]
96
+
97
+ # return [
98
+ # cl.ChatProfile(
99
+ # name="Broomva Book Agent Lite",
100
+ # markdown_description="The underlying LLM model is **GPT-3.5**.",
101
+ # # icon="https://picsum.photos/200",
102
+ # ),
103
+ # cl.ChatProfile(
104
+ # name="Broomva Book Agent Turbo",
105
+ # markdown_description="The underlying LLM model is **GPT-4 Turbo**.",
106
+ # # icon="https://picsum.photos/250",
107
+ # ),
108
+ # ]
109
 
110
 
111
  @cl.on_settings_update
 
115
 
116
  @cl.on_chat_start
117
  async def init():
118
+ cl.AppUser(username="Broomva", role="ADMIN", provider="header")
119
  settings = await cl.ChatSettings(
120
  [
121
  Select(
 
149
  ]
150
  ).send()
151
 
152
+ # chat_profile = cl.user_session.get("chat_profile")
153
 
154
+ # if chat_profile == "Broomva Book Agent Lite":
155
+ # settings["model"] = "gpt-3.5-turbo"
156
+ # elif chat_profile == "Broomva Book Agent Turbo":
157
+ # settings["model"] = "gpt-4-1106-preview"
158
 
159
  chain = RetrievalQAWithSourcesChain.from_chain_type(
160
  ChatOpenAI(
 
179
  )
180
  cb.answer_reached = True
181
 
182
+ await chain.acall(message.content, callbacks=[cb])
183
 
184
+ # if cb.has_streamed_final_answer:
185
+ # await cb.final_stream.update()
186
+ # else:
187
+ #
188
+ #answer = res["answer"]
189
+ #await cl.Message(
190
+ # content=answer,
191
+ #).send()
192
 
193
 
194
  # # Instantiate the LLM