Spaces:
Sleeping
Sleeping
Sneha Dixit commited on
Commit ·
097df9f
1
Parent(s): 1301703
[ADDED] config env
Browse files- client.py +5 -4
- configenv.py +18 -0
- constants.py +1 -1
client.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
from openai import AzureOpenAI
|
| 2 |
import constants
|
|
|
|
| 3 |
|
| 4 |
client = AzureOpenAI(
|
| 5 |
-
api_key=
|
| 6 |
-
api_version=
|
| 7 |
-
azure_endpoint =
|
| 8 |
)
|
| 9 |
|
| 10 |
prompt = 'Write a tagline for an ice cream shop.'
|
| 11 |
|
| 12 |
response = client.completions.create(
|
| 13 |
-
model=
|
| 14 |
prompt=prompt,
|
| 15 |
max_tokens=50,
|
| 16 |
n=1,
|
|
|
|
| 1 |
from openai import AzureOpenAI
|
| 2 |
import constants
|
| 3 |
+
from .configenv import config
|
| 4 |
|
| 5 |
client = AzureOpenAI(
|
| 6 |
+
api_key=config.API_KEY,
|
| 7 |
+
api_version=config.MODEL_VERSION_ID,
|
| 8 |
+
azure_endpoint = config.END_POINT
|
| 9 |
)
|
| 10 |
|
| 11 |
prompt = 'Write a tagline for an ice cream shop.'
|
| 12 |
|
| 13 |
response = client.completions.create(
|
| 14 |
+
model=config.MODEL_NAME,
|
| 15 |
prompt=prompt,
|
| 16 |
max_tokens=50,
|
| 17 |
n=1,
|
configenv.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
AZURE_OPENAI_API_KEY=''
|
| 2 |
AZURE_OPENAI_ENDPOINT=''
|
| 3 |
-
API_VERSION='
|
|
|
|
| 1 |
AZURE_OPENAI_API_KEY=''
|
| 2 |
AZURE_OPENAI_ENDPOINT=''
|
| 3 |
+
API_VERSION=''
|