Minor improvements including consistently setting override to True when loading dotenv
This commit is contained in:
@@ -92,7 +92,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from hello import app, hello"
|
||||
"from hello import app, hello, hello_europe"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -119,6 +119,35 @@
|
||||
"reply"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a1c075e9-49c7-4ebd-812f-83196d32de32",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Added thanks to student Tue H.\n",
|
||||
"\n",
|
||||
"If you look in hello.py, I've added a simple function hello_europe\n",
|
||||
"\n",
|
||||
"That uses the decorator: \n",
|
||||
"`@app.function(image=image, region=\"eu\")`\n",
|
||||
"\n",
|
||||
"See the result below! More region specific settings are [here](https://modal.com/docs/guide/region-selection)\n",
|
||||
"\n",
|
||||
"Note that it does consume marginally more credits to specify a region."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b027da1a-c79d-42cb-810d-32ddca31aa02",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"with app.run():\n",
|
||||
" reply=hello_europe.remote()\n",
|
||||
"reply"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "22e8d804-c027-45fb-8fef-06e7bba6295a",
|
||||
@@ -247,8 +276,8 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# You can also run \"modal deploy pricer_service2\" at the command line in an activated environment\n",
|
||||
"!modal deploy pricer_service2"
|
||||
"# You can also run \"modal deploy -m pricer_service2\" at the command line in an activated environment\n",
|
||||
"!modal deploy -m pricer_service2"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -264,6 +293,16 @@
|
||||
"print(reply)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c29b8c58-4cb7-44b0-ab7e-6469d3a318e8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install --upgrade modal"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9c1b1451-6249-4462-bf2d-5937c059926c",
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
"source": [
|
||||
"# environment\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n",
|
||||
"os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')\n",
|
||||
"DB = \"products_vectorstore\""
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
"source": [
|
||||
"# environment\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n",
|
||||
"os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')"
|
||||
]
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
"source": [
|
||||
"# environment\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n",
|
||||
"os.environ['HF_TOKEN'] = os.getenv('HF_TOKEN', 'your-key-if-not-using-env')"
|
||||
]
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
"source": [
|
||||
"# Initialize and constants\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n",
|
||||
"MODEL = 'gpt-4o-mini'\n",
|
||||
"openai = OpenAI()"
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"load_dotenv()\n",
|
||||
"load_dotenv(override=True)\n",
|
||||
"DB = \"products_vectorstore\""
|
||||
]
|
||||
},
|
||||
|
||||
@@ -16,3 +16,14 @@ def hello() -> str:
|
||||
data = response.json()
|
||||
city, region, country = data['city'], data['region'], data['country']
|
||||
return f"Hello from {city}, {region}, {country}!!"
|
||||
|
||||
# New - added thanks to student Tue H.!
|
||||
|
||||
@app.function(image=image, region="eu")
|
||||
def hello_europe() -> str:
|
||||
import requests
|
||||
|
||||
response = requests.get('https://ipinfo.io/json')
|
||||
data = response.json()
|
||||
city, region, country = data['city'], data['region'], data['country']
|
||||
return f"Hello from {city}, {region}, {country}!!"
|
||||
|
||||
@@ -24,7 +24,6 @@ FINETUNED_DIR = MODEL_DIR + FINETUNED_MODEL
|
||||
QUESTION = "How much does this cost to the nearest dollar?"
|
||||
PREFIX = "Price is $"
|
||||
|
||||
|
||||
@app.cls(image=image, secrets=secrets, gpu=GPU, timeout=1800)
|
||||
class Pricer:
|
||||
@modal.build()
|
||||
|
||||
Reference in New Issue
Block a user