hamza82 commited on
Commit
ec64bd2
·
verified ·
1 Parent(s): 801579d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -71
app.py CHANGED
@@ -1,67 +1,67 @@
1
- import os
2
- import logging
3
- from fastapi import FastAPI
4
- from fastapi.middleware.cors import CORSMiddleware
5
- from fastapi.responses import JSONResponse, FileResponse
6
- from fastapi.staticfiles import StaticFiles
7
- from dotenv import load_dotenv
8
- from openai import AsyncOpenAI
9
-
10
- # Import your custom modules
11
- from chainlit.auth import create_jwt
12
- import chainlit as cl
13
- import uvicorn
14
- # Load environment variables from .env file
15
- load_dotenv()
16
-
17
- # Initialize logging
18
- logging.basicConfig(level=logging.INFO)
19
- logger = logging.getLogger(__name__) # Use __name__ to get the root logger
20
-
21
- # Initialize FastAPI app
22
- app = FastAPI()
23
 
24
- # # CORS middleware setup
25
- # app.add_middleware(
26
- # CORSMiddleware,
27
- # allow_origins=["*"], # Specify domains or use ["*"] for open access
28
- # allow_credentials=True,
29
- # allow_methods=["*"], # Specify methods or use ["*"] for all methods
30
- # allow_headers=["*"], # Specify headers or use ["*"] for all headers
31
- # )
32
 
33
- client = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
 
 
34
 
35
- settings = {
36
- "model": "gpt-3.5-turbo",
37
- "temperature": 0.7,
38
- "max_tokens": 500,
39
- "top_p": 1,
40
- "frequency_penalty": 0,
41
- "presence_penalty": 0,
42
- }
43
 
44
- app.mount("/", StaticFiles(directory="static", html=True), name="static")
45
- logger.info("Static files are being served from the 'static' directory.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- @app.get("/")
48
- def read_root():
49
- # Serve your static HTML file at the root.
50
- logger.info(f"Serving static file for path")
51
- return FileResponse('static/index.html')
52
 
53
- @app.get("/api")
54
- def read_api():
55
- # This endpoint simply returns a JSON message.
56
- return {"message": "Hello from the FastAPI API!"}
57
 
58
- @app.get("/custom-auth")
59
- def custom_auth():
60
- # Verify the user's identity with custom logic.
61
- token = create_jwt(cl.User(identifier="Test User"))
62
- logger.info("Custom auth token generated.")
63
- print("teeeeeee", token)
64
- return JSONResponse({"token": token})
65
 
66
  # @cl.on_chat_start
67
  # async def on_chat_start():
@@ -94,23 +94,51 @@ def custom_auth():
94
 
95
  #########################################################################################################################
96
 
97
- # from fastapi import FastAPI
98
- # from fastapi.staticfiles import StaticFiles
99
- # from fastapi.responses import FileResponse, JSONResponse
100
 
101
- # app = FastAPI()
 
 
 
 
 
102
 
103
- # # Assuming your static files are in a directory named 'static'.
104
- # app.mount("/static", StaticFiles(directory="static"), name="static")
 
105
 
106
- # @app.get("/")
107
- # def read_root():
108
- # # Serve your static HTML file at the root.
109
- # return FileResponse('static/index.html')
110
 
111
- # @app.get("/api")
112
- # def read_api():
113
- # # This endpoint simply returns a JSON message.
114
- # return {"message": "Hello from the FastAPI API!"}
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import os
2
+ # import logging
3
+ # from fastapi import FastAPI
4
+ # from fastapi.middleware.cors import CORSMiddleware
5
+ # from fastapi.responses import JSONResponse, FileResponse
6
+ # from fastapi.staticfiles import StaticFiles
7
+ # from dotenv import load_dotenv
8
+ # from openai import AsyncOpenAI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # # Import your custom modules
11
+ # from chainlit.auth import create_jwt
12
+ # import chainlit as cl
13
+ # import uvicorn
14
+ # # Load environment variables from .env file
15
+ # load_dotenv()
 
 
16
 
17
+ # # Initialize logging
18
+ # logging.basicConfig(level=logging.INFO)
19
+ # logger = logging.getLogger(__name__) # Use __name__ to get the root logger
20
 
21
+ # # Initialize FastAPI app
22
+ # app = FastAPI()
 
 
 
 
 
 
23
 
24
+ # # # CORS middleware setup
25
+ # # app.add_middleware(
26
+ # # CORSMiddleware,
27
+ # # allow_origins=["*"], # Specify domains or use ["*"] for open access
28
+ # # allow_credentials=True,
29
+ # # allow_methods=["*"], # Specify methods or use ["*"] for all methods
30
+ # # allow_headers=["*"], # Specify headers or use ["*"] for all headers
31
+ # # )
32
+
33
+ # client = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
34
+
35
+ # settings = {
36
+ # "model": "gpt-3.5-turbo",
37
+ # "temperature": 0.7,
38
+ # "max_tokens": 500,
39
+ # "top_p": 1,
40
+ # "frequency_penalty": 0,
41
+ # "presence_penalty": 0,
42
+ # }
43
+
44
+ # app.mount("/", StaticFiles(directory="static", html=True), name="static")
45
+ # logger.info("Static files are being served from the 'static' directory.")
46
 
47
+ # @app.get("/")
48
+ # def read_root():
49
+ # # Serve your static HTML file at the root.
50
+ # logger.info(f"Serving static file for path")
51
+ # return FileResponse('static/index.html')
52
 
53
+ # @app.get("/api")
54
+ # def read_api():
55
+ # # This endpoint simply returns a JSON message.
56
+ # return {"message": "Hello from the FastAPI API!"}
57
 
58
+ # @app.get("/custom-auth")
59
+ # def custom_auth():
60
+ # # Verify the user's identity with custom logic.
61
+ # token = create_jwt(cl.User(identifier="Test User"))
62
+ # logger.info("Custom auth token generated.")
63
+ # print("teeeeeee", token)
64
+ # return JSONResponse({"token": token})
65
 
66
  # @cl.on_chat_start
67
  # async def on_chat_start():
 
94
 
95
  #########################################################################################################################
96
 
97
+ from fastapi import FastAPI
98
+ from fastapi.staticfiles import StaticFiles
99
+ from fastapi.responses import FileResponse, JSONResponse
100
 
101
+ # Import your custom modules
102
+ from chainlit.auth import create_jwt
103
+ import chainlit as cl
104
+ import uvicorn
105
+ # Load environment variables from .env file
106
+ load_dotenv()
107
 
108
+ # Initialize logging
109
+ logging.basicConfig(level=logging.INFO)
110
+ logger = logging.getLogger(__name__) # Use __name__ to get the root logger
111
 
112
+ app = FastAPI()
 
 
 
113
 
114
+ client = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
 
 
 
115
 
116
+ settings = {
117
+ "model": "gpt-3.5-turbo",
118
+ "temperature": 0.7,
119
+ "max_tokens": 500,
120
+ "top_p": 1,
121
+ "frequency_penalty": 0,
122
+ "presence_penalty": 0,
123
+ }
124
+
125
+ # Assuming your static files are in a directory named 'static'.
126
+ app.mount("/static", StaticFiles(directory="static"), name="static")
127
+
128
+ @app.get("/")
129
+ def read_root():
130
+ # Serve your static HTML file at the root.
131
+ return FileResponse('static/index.html')
132
 
133
+ @app.get("/api")
134
+ def read_api():
135
+ # This endpoint simply returns a JSON message.
136
+ return {"message": "Hello from the FastAPI API!"}
137
+
138
+ @app.get("/custom-auth")
139
+ def custom_auth():
140
+ # Verify the user's identity with custom logic.
141
+ token = create_jwt(cl.User(identifier="Test User"))
142
+ logger.info("Custom auth token generated.")
143
+ print("teeeeeee", token)
144
+ return JSONResponse({"token": token})