Skip to content

Commit

Permalink
Merge pull request #8 from hookdeck/tutorial
Browse files Browse the repository at this point in the history
Updates following tutorial review
  • Loading branch information
leggetter authored Nov 19, 2024
2 parents 5fb280c + f60057e commit 524609f
Show file tree
Hide file tree
Showing 18 changed files with 1,406 additions and 312 deletions.
11 changes: 10 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ MONGODB_CONNECTION_URI=""
# Hookdeck Project API Key
# Hookdeck Dashboard -> Settings -> Secrets
HOOKDECK_PROJECT_API_KEY=""
HOOKDECK_WEBHOOK_SECRET=

# Replicate API Token
REPLICATE_API_TOKEN=""
# Replicate Dashboard -> Account Settings -> Webhooks -> Show signing key
REPLICATE_WEBHOOKS_SECRET

# Note: The following are auto-populated
# when you run create-hookdeck-connections.py

# Hookdeck Source inbound queue
HOOKDECK_REPLICATE_API_QUEUE_API_KEY=

# Hookdeck Source URLs
# These will be automatically populated for you in the next step
HOOKDECK_REPLICATE_API_QUEUE_URL=
AUDIO_WEBHOOK_URL=""
EMBEDDINGS_WEBHOOK_URL=""
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ poetry run python -m flask --app app --debug run
Create localtunnels to receive webhooks from the two Hookdeck Connections:

```sh
hookdeck listen '*' 5000
hookdeck listen 5000 '*'
```

Navigate to `localhost:5000` within your web browser.
Expand Down
51 changes: 27 additions & 24 deletions allthethings/generators.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import replicate

import httpx
from config import Config


class AsyncEmbeddingsGenerator:
def __init__(self):
self.WEBHOOK_URL = Config.EMBEDDINGS_WEBHOOK_URL
self.model = replicate.models.get("replicate/all-mpnet-base-v2")
self.version = self.model.versions.get(
"b6b7585c9640cd7a9572c6e129c9549d79c9c31f0d3fdce7baac7c67ca38f305"
)

def generate(self, text):
input = {"text": text}

prediction = replicate.predictions.create(
version=self.version,
input=input,
webhook=self.WEBHOOK_URL,
webhook_events_filter=["completed"],
def generate(self, id, text):
payload = {
"version": "b6b7585c9640cd7a9572c6e129c9549d79c9c31f0d3fdce7baac7c67ca38f305",
"input": {"text": text},
"webhook": f"{Config.EMBEDDINGS_WEBHOOK_URL}/{id}",
"webhook_events_filter": ["completed"],
}

response = httpx.request(
"POST",
f"{Config.HOOKDECK_REPLICATE_API_QUEUE_URL}/predictions",
headers=Config.HOOKDECK_QUEUE_AUTH_HEADERS,
json=payload,
)

return prediction
return response.json()


class SyncEmbeddingsGenerator:

def generate(self, text):

input = {"text": text}
output = replicate.run(
"replicate/all-mpnet-base-v2:b6b7585c9640cd7a9572c6e129c9549d79c9c31f0d3fdce7baac7c67ca38f305",
input=input,
payload = {
"version": "b6b7585c9640cd7a9572c6e129c9549d79c9c31f0d3fdce7baac7c67ca38f305",
"input": {"text": text},
}

response = httpx.request(
"POST",
"https://api.replicate.com/v1/predictions",
headers={**Config.REPLICATE_API_AUTH_HEADERS, "Prefer": "wait"},
json=payload,
timeout=180,
)

return output
return response.json()
31 changes: 15 additions & 16 deletions allthethings/processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import replicate

import httpx
from config import Config


Expand All @@ -17,14 +16,7 @@ def get_asset_processor(


class AudioProcessor:
def __init__(self):
self.WEBHOOK_URL = Config.AUDIO_WEBHOOK_URL
self.model = replicate.models.get("openai/whisper")
self.version = self.model.versions.get(
"cdd97b257f93cb89dede1c7584e3f3dfc969571b357dbcee08e793740bedd854"
)

def process(self, url):
def process(self, id, url):
input = {
"audio": url,
"model": "large-v3",
Expand All @@ -40,11 +32,18 @@ def process(self, url):
"temperature_increment_on_fallback": 0.2,
}

prediction = replicate.predictions.create(
version=self.version,
input=input,
webhook=self.WEBHOOK_URL,
webhook_events_filter=["completed"],
payload = {
"version": "cdd97b257f93cb89dede1c7584e3f3dfc969571b357dbcee08e793740bedd854",
"input": input,
"webhook": f"{Config.AUDIO_WEBHOOK_URL}/{id}",
"webhook_events_filter": ["completed"],
}

response = httpx.request(
"POST",
f"{Config.HOOKDECK_REPLICATE_API_QUEUE_URL}/predictions",
headers=Config.HOOKDECK_QUEUE_AUTH_HEADERS,
json=payload,
)

return prediction
return response.json()
Loading

0 comments on commit 524609f

Please sign in to comment.