Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev - 1.4.0 #28

Merged
merged 36 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e82bc2
Add streaming support
zaldivards Nov 26, 2023
b8c836e
Remove unused prompts
zaldivards Nov 27, 2023
44fa10b
Update state handlers
zaldivards Nov 27, 2023
98a317e
Add `AsyncCallback` for the agent
zaldivards Nov 27, 2023
3c3984a
Update chatbox
zaldivards Nov 27, 2023
8509578
Remove deprecated code
zaldivards Nov 27, 2023
c8a3f61
Add `general` module
zaldivards Nov 27, 2023
1e8b2bb
Add streaming support for `QA`
zaldivards Nov 27, 2023
a0c1bfe
Rename `general` module to `streaming`
zaldivards Nov 27, 2023
b78a31b
Update the `ask` function
zaldivards Nov 27, 2023
66db0c4
Update text utils
zaldivards Nov 28, 2023
acb1684
Update the `stream` function
zaldivards Nov 28, 2023
703bccb
Update the `ask` function
zaldivards Nov 28, 2023
30aac42
Remove `clean` function
zaldivards Nov 28, 2023
6f58500
Merge pull request #24 from zaldivards/feature/streaming
zaldivards Dec 1, 2023
2529bc9
Update `build_sources` function
zaldivards Dec 18, 2023
9305abf
Update how the sources are streamed
zaldivards Dec 18, 2023
3f1b2d7
Add the `SourcesBox` component
zaldivards Dec 18, 2023
f78fc7a
Add rendering of sources
zaldivards Dec 18, 2023
b53dba8
Update `build_sources` function
zaldivards Feb 10, 2024
440312c
Add state of the latest sources
zaldivards Feb 10, 2024
e36af74
Update sources layout
zaldivards Feb 10, 2024
d00799a
Merge pull request #26 from zaldivards/feature/sourceRendering
zaldivards Feb 12, 2024
3c7b528
Update file uploader
zaldivards Feb 12, 2024
29c5786
Add the `BatchProcessor` class
zaldivards Feb 12, 2024
6339245
Update the `/ingest/` endpoint
zaldivards Feb 12, 2024
8b9b8a4
Fix bug when working with multiple threads
zaldivards Feb 12, 2024
2621722
Add `/check-sources` endpoint
zaldivards Feb 12, 2024
3299493
Update mounted function to check the sources availability
zaldivards Feb 12, 2024
e5f7e9c
Update QA session warnings
zaldivards Feb 12, 2024
2ff4f89
Fix error related to the connection pool
zaldivards Feb 12, 2024
e9a368c
Update the `/ingest/` endpoint
zaldivards Feb 12, 2024
f7b7d28
Update QA messages
zaldivards Feb 12, 2024
933c16a
Update section names
zaldivards Feb 12, 2024
b21a044
Fix bug regarding the `latestSources` state
zaldivards Feb 12, 2024
d1aa05a
Merge pull request #27 from zaldivards/feature/multiIngestion
zaldivards Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update build_sources function
Added logic to ensure sources are not duplicated as during
the generation process they might be  (due to the async behavior)
  • Loading branch information
zaldivards committed Dec 18, 2023
commit 2529bc9133eef616fbd8a7fc3b00ed8645a32f97
2 changes: 1 addition & 1 deletion api/contextqa/models/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SourceFormat(str, Enum):
class Source(BaseModel):
title: str
format_: Annotated[SourceFormat, Field(alias="format")]
content: str | dict
content: str | list


class LLMResult(BaseModel):
Expand Down
43 changes: 29 additions & 14 deletions api/contextqa/utils/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,45 @@ def build_sources(sources: list[Document]) -> list[Source]:
sources transformed into a proper format depending the file type
"""
result = []
processed_sources = set()

for source in sources:
name = source.metadata.pop("source")
source_name = name.split(settings.tmp_separator)[-1]
extension = name.split(".")[-1]

match extension:
case SourceFormat.PDF:
page_number = source.metadata.get("page")
path = Path(name)
pdf = fitz.open(str(path))
page = pdf[page_number]
img_bytes = page.get_pixmap().tobytes()
base64_img = base64.b64encode(img_bytes)
source = Source(title=f"{path.name} - Page {page_number}", format=SourceFormat.PDF, content=base64_img)
title = f"{path.name} - Page {page_number}"
if title not in processed_sources:
pdf = fitz.open(str(path))
page = pdf[page_number]
img_bytes = page.get_pixmap().tobytes()
base64_img = base64.b64encode(img_bytes).decode().replace('"', '\\"')
format_ = SourceFormat.PDF
content = base64_img
case SourceFormat.TXT:
idx = source.metadata.get("idx")
source = Source(
title=f"{source_name} - Segment {idx}", format=SourceFormat.TXT, content=source.page_content
)
title = f"{source_name} - Segment {idx}"
if title not in processed_sources:
format_ = SourceFormat.TXT
content = source.page_content
case SourceFormat.CSV:
row = source.metadata.get("row")
data = {}
for cell in source.page_content.split("\n"):
key, value = cell.split(":", 1)
data[key] = value.strip()
source = Source(title=f"{source_name} - Row {row}", format=SourceFormat.CSV, content=data)
result.append(source.model_dump())
title = f"{source_name} - Row {row}"
format_ = SourceFormat.CSV
if title not in processed_sources:
data = {}
for cell in source.page_content.split("\n"):
key, value = cell.split(":", 1)
data[key] = value.strip()
content = [data]

if title not in processed_sources:
source_data = Source(title=title, format=format_, content=content)
result.append(source_data.model_dump())
processed_sources.add(title)

return result