-
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.
Finalize defichain python integration
- Loading branch information
Showing
8 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
.github/workflows/defichain_python_scraping_production.yml
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,27 @@ | ||
name: Defichain Python scraping Production | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run_script: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
working-directory: ./job | ||
|
||
- name: Run the script | ||
run: python ./job/defichainpython_embedding.py | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
SUPABASE_URL: ${{ vars.PRODUCTION_SUPABASE_API_URL }} | ||
SUPABASE_KEY: ${{ secrets.PRODUCTION_SUPABASE_API_ANON_KEY }} |
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,30 @@ | ||
name: Defichain Python scraping Staging | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run_script: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
working-directory: ./job | ||
|
||
- name: Embeddings for DefichainPython | ||
run: python ./job/defichainpython_embedding.py | ||
env: | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
SUPABASE_URL: ${{ vars.STAGING_SUPABASE_API_URL }} | ||
SUPABASE_KEY: ${{ secrets.STAGING_SUPABASE_API_ANON_KEY }} |
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
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
35 changes: 35 additions & 0 deletions
35
data/supabase/migrations/20231015150642_add_defichain_python_embeddings.sql
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,35 @@ | ||
-- Create a table to store embeddings | ||
create table embeddings_defichain_python ( | ||
id UUID primary key, | ||
content text, -- corresponds to Document.pageContent | ||
metadata jsonb, -- corresponds to Document.metadata | ||
embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed | ||
); | ||
|
||
-- Create a function to search for embeddings | ||
create function match_embeddings_defichain_python ( | ||
query_embedding vector(1536), | ||
match_count int default null, | ||
filter jsonb DEFAULT '{}' | ||
) returns table ( | ||
id uuid, | ||
content text, | ||
metadata jsonb, | ||
similarity float | ||
) | ||
language plpgsql | ||
as $$ | ||
#variable_conflict use_column | ||
begin | ||
return query | ||
select | ||
id, | ||
content, | ||
metadata, | ||
1 - (embeddings_defichain_python.embedding <=> query_embedding) as similarity | ||
from embeddings_defichain_python | ||
where metadata @> filter | ||
order by embeddings_defichain_python.embedding <=> query_embedding | ||
limit match_count; | ||
end; | ||
$$; |
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