Spaces:
Sleeping
Sleeping
Sneha Dixit
commited on
Commit
•
283373b
1
Parent(s):
561dc24
[UPDATED] secret handling
Browse files- Dockerfile +11 -2
- auth.py +2 -1
- client.py +5 -6
- configenv.py +0 -18
- constants.py +0 -3
Dockerfile
CHANGED
@@ -7,7 +7,16 @@ WORKDIR /
|
|
7 |
RUN pip install --no-cache-dir --upgrade -r /requirements.txt
|
8 |
|
9 |
# Get secrets
|
10 |
-
RUN --mount=type=secret,id=test,mode=0444,required=true
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
7 |
RUN pip install --no-cache-dir --upgrade -r /requirements.txt
|
8 |
|
9 |
# Get secrets
|
10 |
+
RUN --mount=type=secret,id=test,mode=0444,required=true
|
11 |
+
|
12 |
+
RUN --mount=type=secret,id=OPENAI_API_KEY,mode=0444,required=true
|
13 |
+
|
14 |
+
RUN --mount=type=secret,id=MODEL_VERSION,mode=0444,required=true
|
15 |
+
|
16 |
+
RUN --mount=type=secret,id=END_POINT,mode=0444,required=true
|
17 |
+
|
18 |
+
RUN --mount=type=secret,id=MODEL_NAME,mode=0444,required=true
|
19 |
+
|
20 |
+
RUN --mount=type=secret,id=API_KEY,mode=0444,required=true
|
21 |
|
22 |
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]
|
auth.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
from fastapi.security.api_key import APIKeyHeader
|
2 |
from fastapi import Security, HTTPException
|
|
|
3 |
|
4 |
-
API_Keys = [
|
5 |
api_key_header = APIKeyHeader(name="x-api-key", auto_error=False)
|
6 |
|
7 |
async def api_key_auth(api_key: str = Security(api_key_header)):
|
|
|
1 |
from fastapi.security.api_key import APIKeyHeader
|
2 |
from fastapi import Security, HTTPException
|
3 |
+
import os
|
4 |
|
5 |
+
API_Keys = [os.environ.get('API_KEY')]
|
6 |
api_key_header = APIKeyHeader(name="x-api-key", auto_error=False)
|
7 |
|
8 |
async def api_key_auth(api_key: str = Security(api_key_header)):
|
client.py
CHANGED
@@ -1,17 +1,16 @@
|
|
1 |
from openai import AzureOpenAI
|
2 |
-
import
|
3 |
-
from .configenv import config
|
4 |
|
5 |
client = AzureOpenAI(
|
6 |
-
api_key=
|
7 |
-
api_version=
|
8 |
-
azure_endpoint =
|
9 |
)
|
10 |
|
11 |
prompt = 'Write a tagline for an ice cream shop.'
|
12 |
|
13 |
response = client.completions.create(
|
14 |
-
model=
|
15 |
prompt=prompt,
|
16 |
max_tokens=50,
|
17 |
n=1,
|
|
|
1 |
from openai import AzureOpenAI
|
2 |
+
import os
|
|
|
3 |
|
4 |
client = AzureOpenAI(
|
5 |
+
api_key=os.environ.get('OPENAI_API_KEY'),
|
6 |
+
api_version=os.environ.get('MODEL_VERSION'),
|
7 |
+
azure_endpoint = os.environ.get('END_POINT')
|
8 |
)
|
9 |
|
10 |
prompt = 'Write a tagline for an ice cream shop.'
|
11 |
|
12 |
response = client.completions.create(
|
13 |
+
model=os.environ.get('MODEL_NAME'),
|
14 |
prompt=prompt,
|
15 |
max_tokens=50,
|
16 |
n=1,
|
configenv.py
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
"""Config class for handling env variables.
|
2 |
-
"""
|
3 |
-
from functools import lru_cache
|
4 |
-
from pydantic import BaseSettings
|
5 |
-
|
6 |
-
class Settings(BaseSettings):
|
7 |
-
API_KEY: str
|
8 |
-
END_POINT: str
|
9 |
-
MODEL_NAME: str
|
10 |
-
MODEL_VERSION: str
|
11 |
-
|
12 |
-
class Config:
|
13 |
-
env_file = '.env'
|
14 |
-
|
15 |
-
@lru_cache()
|
16 |
-
def get_settings():
|
17 |
-
return Settings()
|
18 |
-
config = get_settings()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constants.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
AZURE_OPENAI_API_KEY=''
|
2 |
-
AZURE_OPENAI_ENDPOINT=''
|
3 |
-
API_VERSION=''
|
|
|
|
|
|
|
|