Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,8 +13,6 @@ app.secret_key = 'YourSecretKey' # Change this to a real secret key for product
|
|
13 |
|
14 |
# OAuth setup with Authlib
|
15 |
oauth = OAuth(app)
|
16 |
-
|
17 |
-
# Assuming environment variables are set for OAuth
|
18 |
oauth.register(
|
19 |
name='oauth_provider',
|
20 |
client_id=os.getenv("OAUTH_CLIENT_ID"),
|
@@ -43,6 +41,24 @@ def initialize_chainlit():
|
|
43 |
)
|
44 |
)
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
@app.route('/')
|
47 |
def home():
|
48 |
return 'Home - <a href="/login">Login with OAuth Provider</a>'
|
@@ -55,10 +71,10 @@ def login():
|
|
55 |
@app.route('/login/callback')
|
56 |
def authorize():
|
57 |
token = oauth.oauth_provider.authorize_access_token()
|
58 |
-
#
|
59 |
-
# Here, initialize ChainLit or perform actions based on the authenticated user
|
60 |
initialize_chainlit()
|
61 |
return 'Logged in and language model initialized. Proceed with operations.'
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
app.run(debug=True)
|
|
|
|
13 |
|
14 |
# OAuth setup with Authlib
|
15 |
oauth = OAuth(app)
|
|
|
|
|
16 |
oauth.register(
|
17 |
name='oauth_provider',
|
18 |
client_id=os.getenv("OAUTH_CLIENT_ID"),
|
|
|
41 |
)
|
42 |
)
|
43 |
|
44 |
+
# Setup chainlit callbacks
|
45 |
+
@cl.on_chat_start
|
46 |
+
async def on_chat_start():
|
47 |
+
prompt = ChatPromptTemplate.from_messages([("human", "{question}")])
|
48 |
+
runnable = prompt | llm | StrOutputParser()
|
49 |
+
cl.user_session.set("runnable", runnable)
|
50 |
+
|
51 |
+
@cl.on_message
|
52 |
+
async def on_message(message: cl.Message):
|
53 |
+
runnable = cl.user_session.get("runnable") # type: Runnable
|
54 |
+
msg = cl.Message(content="")
|
55 |
+
async for chunk in runnable.astream(
|
56 |
+
{"question": message.content},
|
57 |
+
config=RunnableConfig(callbacks=[cl.LangchainCallbackHandler()]),
|
58 |
+
):
|
59 |
+
await msg.stream_token(chunk)
|
60 |
+
await msg.send()
|
61 |
+
|
62 |
@app.route('/')
|
63 |
def home():
|
64 |
return 'Home - <a href="/login">Login with OAuth Provider</a>'
|
|
|
71 |
@app.route('/login/callback')
|
72 |
def authorize():
|
73 |
token = oauth.oauth_provider.authorize_access_token()
|
74 |
+
# Initialize ChainLit or perform actions based on the authenticated user
|
|
|
75 |
initialize_chainlit()
|
76 |
return 'Logged in and language model initialized. Proceed with operations.'
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
app.run(debug=True)
|
80 |
+
|