Sirorororo commited on
Commit
c6bb0a1
·
1 Parent(s): 32db087

New approach part 3

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -120,20 +120,42 @@
120
 
121
 
122
 
123
- from fastapi import FastAPI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  import httpx
125
 
126
  app = FastAPI()
127
  TARGET_SERVER = "http://localhost:11434"
128
 
129
- @app.get("/proxy/{path:path}")
130
- async def get_proxy_request(path: str):
 
131
  async with httpx.AsyncClient() as client:
132
  response = await client.get(f"{TARGET_SERVER}/{path}")
133
  return response.json()
134
 
135
- @app.post("/proxy/{path:path}")
136
- async def post_proxy_request(path: str):
 
 
137
  async with httpx.AsyncClient() as client:
138
- response = await client.post(f"{TARGET_SERVER}/{path}")
139
  return response.json()
 
120
 
121
 
122
 
123
+ # from fastapi import FastAPI
124
+ # import httpx
125
+
126
+ # app = FastAPI()
127
+ # TARGET_SERVER = "http://localhost:11434"
128
+
129
+ # @app.get("/proxy/{path:path}")
130
+ # async def get_proxy_request(path: str):
131
+ # async with httpx.AsyncClient() as client:
132
+ # response = await client.get(f"{TARGET_SERVER}/{path}")
133
+ # return response.json()
134
+
135
+ # @app.post("/proxy/{path:path}")
136
+ # async def post_proxy_request(path: str):
137
+ # async with httpx.AsyncClient() as client:
138
+ # response = await client.post(f"{TARGET_SERVER}/{path}")
139
+ # return response.json()
140
+
141
+
142
+ from fastapi import FastAPI, Request
143
  import httpx
144
 
145
  app = FastAPI()
146
  TARGET_SERVER = "http://localhost:11434"
147
 
148
+ @app.get("/{path:path}")
149
+ async def proxy_get(path: str):
150
+ """ Forwards GET requests to the target server """
151
  async with httpx.AsyncClient() as client:
152
  response = await client.get(f"{TARGET_SERVER}/{path}")
153
  return response.json()
154
 
155
+ @app.post("/{path:path}")
156
+ async def proxy_post(path: str, request: Request):
157
+ """ Forwards POST requests to the target server """
158
+ data = await request.json() # Get the request body
159
  async with httpx.AsyncClient() as client:
160
+ response = await client.post(f"{TARGET_SERVER}/{path}", json=data)
161
  return response.json()