MAsad789565 commited on
Commit
3fea8a6
1 Parent(s): 5008bbf

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. apis/chat_api.py +12 -4
apis/chat_api.py CHANGED
@@ -6,6 +6,7 @@ import uvicorn
6
 
7
  from pathlib import Path
8
  from fastapi import FastAPI, Depends
 
9
  from fastapi.responses import HTMLResponse
10
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
11
  from pydantic import BaseModel, Field
@@ -25,11 +26,19 @@ class ChatAPIApp:
25
  swagger_ui_parameters={"defaultModelsExpandDepth": -1},
26
  version="1.0",
27
  )
 
28
  self.setup_routes()
29
 
 
 
 
 
 
 
 
 
 
30
  def get_available_models(self):
31
- # https://platform.openai.com/docs/api-reference/models/list
32
- # ANCHOR[id=available-models]: Available models
33
  self.available_models = {
34
  "object": "list",
35
  "data": [
@@ -121,7 +130,6 @@ class ChatAPIApp:
121
  streamer = MessageStreamer(model=item.model)
122
  composer = MessageComposer(model=item.model)
123
  composer.merge(messages=item.messages)
124
- # streamer.chat = stream_chat_mock
125
 
126
  stream_response = streamer.chat_response(
127
  prompt=composer.merged_str,
@@ -220,4 +228,4 @@ if __name__ == "__main__":
220
  # python -m apis.chat_api # [Docker] on product mode
221
  # python -m apis.chat_api -d # [Dev] on develop mode
222
 
223
- os.system("python -m apis.chat_api")
 
6
 
7
  from pathlib import Path
8
  from fastapi import FastAPI, Depends
9
+ from fastapi.middleware.cors import CORSMiddleware
10
  from fastapi.responses import HTMLResponse
11
  from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
12
  from pydantic import BaseModel, Field
 
26
  swagger_ui_parameters={"defaultModelsExpandDepth": -1},
27
  version="1.0",
28
  )
29
+ self.setup_cors()
30
  self.setup_routes()
31
 
32
+ def setup_cors(self):
33
+ self.app.add_middleware(
34
+ CORSMiddleware,
35
+ allow_origins=["*"], # Adjust this to specify allowed origins
36
+ allow_credentials=True,
37
+ allow_methods=["*"],
38
+ allow_headers=["*"],
39
+ )
40
+
41
  def get_available_models(self):
 
 
42
  self.available_models = {
43
  "object": "list",
44
  "data": [
 
130
  streamer = MessageStreamer(model=item.model)
131
  composer = MessageComposer(model=item.model)
132
  composer.merge(messages=item.messages)
 
133
 
134
  stream_response = streamer.chat_response(
135
  prompt=composer.merged_str,
 
228
  # python -m apis.chat_api # [Docker] on product mode
229
  # python -m apis.chat_api -d # [Dev] on develop mode
230
 
231
+ os.system("python -m apis.chat_api")