forked from astronomer/ask-astro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to enable integration between Astronomer, Airflow and Weaviate
- Loading branch information
1 parent
f82ba90
commit ba48fcf
Showing
8 changed files
with
136 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# syntax=docker/dockerfile:1.4 | ||
FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt /app | ||
RUN --mount=type=cache,target=/root/.cache/pip \ | ||
pip3 install -r requirements.txt | ||
|
||
COPY . /app | ||
|
||
ENTRYPOINT ["python3"] | ||
CMD ["app.py"] |
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,56 @@ | ||
import re, os, sys | ||
from urllib.parse import urlparse | ||
import requests | ||
from flask import Flask, request, make_response | ||
app = Flask(__name__) | ||
|
||
TARGET_HOST = os.getenv('REDIRECT_PREFIX', '').rstrip('/') | ||
URL_MATCH = os.getenv('URL_MATCH') | ||
URL_REPLACE = os.getenv('URL_REPLACE') | ||
VERBOSE = os.getenv('VERBOSE', 'false') == 'true' | ||
print("Target host: ", TARGET_HOST, file=sys.stderr) | ||
print("URL match: ", URL_MATCH, file=sys.stderr) | ||
print("URL replace: ", URL_REPLACE, file=sys.stderr) | ||
print("Verbose: ", VERBOSE, file=sys.stderr) | ||
|
||
@app.route('/', defaults={'path':''}, methods=['GET','POST']) | ||
@app.route('/<path:path>', methods=['GET','POST']) | ||
def index(path): | ||
data = request.get_data() | ||
url = new_url(request) | ||
method = request.method | ||
headers = {} | ||
for k, v in request.headers: | ||
if k.lower() == 'authorization': | ||
headers['api-key'] = v.replace('Bearer ', '') | ||
else: | ||
headers[k] = v | ||
headers['Host'] = urlparse(url).netloc | ||
if len(data) > 0: | ||
received = requests.request(method, url, headers=headers, data=data) | ||
else: | ||
received = requests.request(method, url, headers=headers) | ||
response = make_response(received.content) | ||
for k, v in received.headers.items(): | ||
response.headers[k] = v | ||
if VERBOSE: | ||
print("Original headers:", request.headers, file=sys.stderr) | ||
print("Original body:", data, file=sys.stderr) | ||
print("New headers:", headers, file=sys.stderr) | ||
print("New body:", received.content[:1000], file=sys.stderr) | ||
return response | ||
|
||
def new_url(request): | ||
orig_url = "%s" % request.path | ||
url = TARGET_HOST + request.path | ||
if len(request.query_string) != 0: | ||
url = url + '?' + request.query_string.decode('ascii') | ||
orig_url += '?' + request.query_string.decode('ascii') | ||
if URL_MATCH is not None and URL_REPLACE is not None: | ||
url = re.sub(URL_MATCH, URL_REPLACE, url) | ||
if VERBOSE: | ||
print("Original URL: %s\nNew URL: %s" % (orig_url, url), file=sys.stderr) | ||
return url | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=5000) |
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,3 @@ | ||
#!/bin/zsh | ||
|
||
docker build . --tag aiproxy |
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,2 @@ | ||
requests | ||
flask |
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 |
---|---|---|
@@ -1,24 +1,36 @@ | ||
version: '3.1' | ||
networks: | ||
ask-astro_astro_network: | ||
external: true | ||
services: | ||
webserver: | ||
ports: | ||
- 8501:8501 | ||
networks: | ||
- airflow | ||
weaviate: | ||
image: semitechnologies/weaviate:1.21.0 | ||
command: "--host 0.0.0.0 --port '8081' --scheme http" | ||
volumes: | ||
- ${PWD}/include/weaviate/backup:/var/lib/weaviate/backup | ||
environment: | ||
QUERY_DEFAULTS_LIMIT: 25 | ||
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true' | ||
PERSISTENCE_DATA_PATH: '/var/lib/weaviate' | ||
DEFAULT_VECTORIZER_MODULE: 'text2vec-openai' | ||
ENABLE_MODULES: 'text2vec-openai, backup-filesystem, qna-openai, generative-openai, text2vec-cohere, reranker-cohere' | ||
BACKUP_FILESYSTEM_PATH: '/var/lib/weaviate/backup' | ||
CLUSTER_HOSTNAME: 'node1' | ||
ports: | ||
- 8081:8081 | ||
- ask-astro_astro_network | ||
triggerer: | ||
networks: | ||
- ask-astro_astro_network | ||
scheduler: | ||
networks: | ||
- ask-astro_astro_network | ||
postgres: | ||
networks: | ||
- airflow | ||
- ask-astro_astro_network | ||
# weaviate: | ||
# image: semitechnologies/weaviate:1.21.0 | ||
# command: "--host 0.0.0.0 --port '8081' --scheme http" | ||
# volumes: | ||
# - ${PWD}/include/weaviate/backup:/var/lib/weaviate/backup | ||
# environment: | ||
# QUERY_DEFAULTS_LIMIT: 25 | ||
# AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true' | ||
# PERSISTENCE_DATA_PATH: '/var/lib/weaviate' | ||
# DEFAULT_VECTORIZER_MODULE: 'text2vec-openai' | ||
# ENABLE_MODULES: 'text2vec-openai, backup-filesystem, qna-openai, generative-openai, text2vec-cohere, reranker-cohere' | ||
# BACKUP_FILESYSTEM_PATH: '/var/lib/weaviate/backup' | ||
# CLUSTER_HOSTNAME: 'node1' | ||
# ports: | ||
# - 8081:8081 | ||
# networks: | ||
# - airflow |
Empty file.
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