Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
c5dc6863
Commit
c5dc6863
authored
1 year ago
by
timothycarambat
Browse files
Options
Downloads
Patches
Plain Diff
patch link scrape tool schema
parent
085745c5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
collector/scripts/link.py
+1
-7
1 addition, 7 deletions
collector/scripts/link.py
collector/scripts/link_utils.py
+8
-0
8 additions, 0 deletions
collector/scripts/link_utils.py
with
9 additions
and
7 deletions
collector/scripts/link.py
+
1
−
7
View file @
c5dc6863
...
@@ -2,7 +2,7 @@ import os, json, tempfile
...
@@ -2,7 +2,7 @@ import os, json, tempfile
from
urllib.parse
import
urlparse
from
urllib.parse
import
urlparse
from
requests_html
import
HTMLSession
from
requests_html
import
HTMLSession
from
langchain.document_loaders
import
UnstructuredHTMLLoader
from
langchain.document_loaders
import
UnstructuredHTMLLoader
from
.link_utils
import
append_meta
from
.link_utils
import
append_meta
from
.utils
import
tokenize
,
ada_v2_cost
from
.utils
import
tokenize
,
ada_v2_cost
import
requests
import
requests
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
...
@@ -47,10 +47,6 @@ def link():
...
@@ -47,10 +47,6 @@ def link():
os
.
makedirs
(
transaction_output_dir
)
os
.
makedirs
(
transaction_output_dir
)
full_text
=
append_meta
(
req
,
full_text
)
full_text
=
append_meta
(
req
,
full_text
)
tokenCount
=
len
(
tokenize
(
full_text
))
link
[
'
pageContent
'
]
=
full_text
link
[
'
token_count_estimate
'
]
=
tokenCount
with
open
(
f
"
{
output_path
}
/
{
output_filename
}
"
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
file
:
with
open
(
f
"
{
output_path
}
/
{
output_filename
}
"
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
file
:
json
.
dump
(
link
,
file
,
ensure_ascii
=
True
,
indent
=
4
)
json
.
dump
(
link
,
file
,
ensure_ascii
=
True
,
indent
=
4
)
...
@@ -159,8 +155,6 @@ def parse_links(links):
...
@@ -159,8 +155,6 @@ def parse_links(links):
full_text
=
append_meta
(
req
,
full_text
)
full_text
=
append_meta
(
req
,
full_text
)
tokenCount
=
len
(
tokenize
(
full_text
))
tokenCount
=
len
(
tokenize
(
full_text
))
link
[
'
pageContent
'
]
=
full_text
link
[
'
token_count_estimate
'
]
=
tokenCount
totalTokens
+=
tokenCount
totalTokens
+=
tokenCount
with
open
(
f
"
{
output_path
}
/
{
output_filename
}
"
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
file
:
with
open
(
f
"
{
output_path
}
/
{
output_filename
}
"
,
'
w
'
,
encoding
=
'
utf-8
'
)
as
file
:
...
...
This diff is collapsed.
Click to expand it.
collector/scripts/link_utils.py
+
8
−
0
View file @
c5dc6863
import
json
import
json
from
datetime
import
datetime
from
datetime
import
datetime
from
dotenv
import
load_dotenv
from
dotenv
import
load_dotenv
from
.watch.utils
import
guid
from
.utils
import
tokenize
load_dotenv
()
load_dotenv
()
def
append_meta
(
request
,
text
,
metadata_only
=
False
):
def
append_meta
(
request
,
text
,
metadata_only
=
False
):
meta
=
{
meta
=
{
'
id
'
:
guid
(),
'
url
'
:
request
.
url
,
'
url
'
:
request
.
url
,
'
title
'
:
request
.
html
.
find
(
'
title
'
,
first
=
True
).
text
if
len
(
request
.
html
.
find
(
'
title
'
))
!=
0
else
''
,
'
title
'
:
request
.
html
.
find
(
'
title
'
,
first
=
True
).
text
if
len
(
request
.
html
.
find
(
'
title
'
))
!=
0
else
''
,
'
docAuthor
'
:
'
N/A
'
,
'
docSource
'
:
'
webpage
'
,
'
chunkSource
'
:
request
.
url
,
'
description
'
:
request
.
html
.
find
(
'
meta[name=
"
description
"
]
'
,
first
=
True
).
attrs
.
get
(
'
content
'
)
if
request
.
html
.
find
(
'
meta[name=
"
description
"
]
'
,
first
=
True
)
!=
None
else
''
,
'
description
'
:
request
.
html
.
find
(
'
meta[name=
"
description
"
]
'
,
first
=
True
).
attrs
.
get
(
'
content
'
)
if
request
.
html
.
find
(
'
meta[name=
"
description
"
]
'
,
first
=
True
)
!=
None
else
''
,
'
published
'
:
request
.
html
.
find
(
'
meta[property=
"
article:published_time
"
]
'
,
first
=
True
).
attrs
.
get
(
'
content
'
)
if
request
.
html
.
find
(
'
meta[property=
"
article:published_time
"
]
'
,
first
=
True
)
!=
None
else
datetime
.
today
().
strftime
(
'
%Y-%m-%d %H:%M:%S
'
),
'
published
'
:
request
.
html
.
find
(
'
meta[property=
"
article:published_time
"
]
'
,
first
=
True
).
attrs
.
get
(
'
content
'
)
if
request
.
html
.
find
(
'
meta[property=
"
article:published_time
"
]
'
,
first
=
True
)
!=
None
else
datetime
.
today
().
strftime
(
'
%Y-%m-%d %H:%M:%S
'
),
'
wordCount
'
:
len
(
text
.
split
(
'
'
)),
'
wordCount
'
:
len
(
text
.
split
(
'
'
)),
'
pageContent
'
:
text
,
'
token_count_estimate
'
:
len
(
tokenize
(
text
)),
}
}
return
"
Article JSON Metadata:
\n
"
+
json
.
dumps
(
meta
)
+
"
\n\n\n
Text Content:
\n
"
+
text
if
metadata_only
==
False
else
meta
return
"
Article JSON Metadata:
\n
"
+
json
.
dumps
(
meta
)
+
"
\n\n\n
Text Content:
\n
"
+
text
if
metadata_only
==
False
else
meta
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment