Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,38 @@ from chainlit.playground.config import add_llm_provider
|
|
| 10 |
from chainlit.playground.providers.langchain import LangchainGenericProvider
|
| 11 |
import chainlit as cl
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Instantiate the LLM
|
| 14 |
llm = HuggingFaceHub(
|
| 15 |
model_kwargs={"max_length": 500},
|
|
|
|
| 10 |
from chainlit.playground.providers.langchain import LangchainGenericProvider
|
| 11 |
import chainlit as cl
|
| 12 |
|
| 13 |
+
import os
|
| 14 |
+
from authlib import OAuth2Session # This is a placeholder for whatever OAuth library you're using
|
| 15 |
+
|
| 16 |
+
# Retrieving environment variables
|
| 17 |
+
OAUTH_CLIENT_ID = os.getenv("OAUTH_CLIENT_ID")
|
| 18 |
+
OAUTH_CLIENT_SECRET = os.getenv("OAUTH_CLIENT_SECRET")
|
| 19 |
+
OAUTH_SCOPES = os.getenv("OAUTH_SCOPES").split(',') # Assuming OAUTH_SCOPES is a comma-separated list
|
| 20 |
+
OPENID_PROVIDER_URL = os.getenv("OPENID_PROVIDER_URL")
|
| 21 |
+
SPACE_HOST = os.getenv("SPACE_HOST")
|
| 22 |
+
|
| 23 |
+
# Constructing the redirect URL using the SPACE_HOST variable
|
| 24 |
+
redirect_uri = f"https://{SPACE_HOST}/login/callback"
|
| 25 |
+
|
| 26 |
+
# Initializing the OAuth client/session with the retrieved environment variables
|
| 27 |
+
oauth_client = OAuth2Session(client_id=OAUTH_CLIENT_ID,
|
| 28 |
+
redirect_uri=redirect_uri,
|
| 29 |
+
scope=OAUTH_SCOPES)
|
| 30 |
+
|
| 31 |
+
# Redirect the user to the authorization URL
|
| 32 |
+
authorization_url, state = oauth_client.authorization_url(OPENID_PROVIDER_URL + '/authorize')
|
| 33 |
+
|
| 34 |
+
# Note: The actual redirect and callback handling will depend on your web framework (e.g., Flask, Django)
|
| 35 |
+
|
| 36 |
+
# After the user authorizes your app and is redirected back to your redirect_uri,
|
| 37 |
+
# you would exchange the authorization code for an access token
|
| 38 |
+
oauth_client.fetch_token(OPENID_PROVIDER_URL + '/token',
|
| 39 |
+
client_secret=OAUTH_CLIENT_SECRET,
|
| 40 |
+
authorization_response='URL where user was redirected')
|
| 41 |
+
|
| 42 |
+
# Now you can use oauth_client to make authorized requests on behalf of the user
|
| 43 |
+
|
| 44 |
+
|
| 45 |
# Instantiate the LLM
|
| 46 |
llm = HuggingFaceHub(
|
| 47 |
model_kwargs={"max_length": 500},
|