Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

fix(api): annotations replacement text contains file ids #1201

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions src/leapfrogai_api/backend/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ def from_text_to_message(text: str, search_responses: SearchResponse | None) ->
The OpenAI compliant Message object
"""

all_file_ids: str = ""
all_citations = ""
all_vector_ids: list[str] = []
annotations: list[FileCitationAnnotation | FilePathAnnotation] = []

if search_responses:
for search_response in search_responses.data:
all_file_ids += f"[{search_response.file_id}]"
all_vector_ids.append(search_response.id)
file_name = search_response.metadata.get("source", "source")
replacement_text = f"【4:0†{file_name}】" # TODO: What should these numbers be? https://github.com/defenseunicorns/leapfrogai/issues/1110
annotations.append(
FileCitationAnnotation(
text=f"【4:0†{file_name}】", # TODO: What should these numbers be? https://github.com/defenseunicorns/leapfrogai/issues/1110
text=replacement_text,
file_citation=FileCitation(
file_id=search_response.file_id, quote=search_response.content
),
Expand All @@ -80,10 +80,12 @@ def from_text_to_message(text: str, search_responses: SearchResponse | None) ->
)
)

all_citations += replacement_text

message_content: TextContentBlock = TextContentBlock(
text=Text(
annotations=annotations,
value=text + all_file_ids,
value=text + all_citations, # TODO: Replace with find/replace test
),
type="text",
)
Expand Down