-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92bc89b
commit 2b80ee0
Showing
5 changed files
with
593 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
from substrate.nodes import Llama3Instruct8B | ||
|
||
# add parent dir to sys.path to make 'substrate' importable | ||
parent_dir = Path(__file__).resolve().parent.parent.parent.parent | ||
sys.path.insert(0, str(parent_dir)) | ||
|
||
api_key = os.environ.get("SUBSTRATE_API_KEY") | ||
if api_key is None: | ||
raise EnvironmentError("No SUBSTRATE_API_KEY set") | ||
|
||
from fastapi import FastAPI | ||
from fastapi.responses import StreamingResponse | ||
|
||
from substrate import Substrate, Llama3Instruct8B | ||
|
||
app = FastAPI() | ||
substrate = Substrate(api_key=api_key, timeout=60 * 5) | ||
|
||
@app.get("/qotd") | ||
def quote_of_the_day(): | ||
quote = Llama3Instruct8B(prompt="What's an inspirational quote of the day?") | ||
|
||
response = substrate.stream(quote) | ||
|
||
return StreamingResponse(response.iter_events(), media_type="text/event-stream") |
Oops, something went wrong.