Skip to content

Commit

Permalink
update with get attachmeents by type (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
jitingxu1 authored Mar 23, 2024
1 parent ed0ca32 commit 58c8bd1
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/ibis_birdbrain/tasks/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,14 @@ def __call__(self, message: Message) -> Message:
log.info("Text to SQL task")

# get the database attachment and table attachments
# TODO: add proper methods for this
table_attachments = Attachments()
database_attachment = None
dialect = "duckdb"
for attachment in message.attachments:
if isinstance(message.attachments[attachment], DatabaseAttachment):
database_attachment = message.attachments[attachment]
dialect = database_attachment.open().name
elif isinstance(message.attachments[attachment], TableAttachment):
table_attachments.append(message.attachments[attachment])

assert len(table_attachments) > 0, "No table attachments found"
table_attachments = message.attachments.get_attachment_by_type(TableAttachment)
database_attachment = message.attachments.get_attachment_by_type(DatabaseAttachment)

assert table_attachments is not None, "No table attachments found"
assert database_attachment is not None, "No database attachment found"

dialect = database_attachment.open().name

# generate the SQL
sql = self.text_to_sql(
text=message.body,
Expand Down

0 comments on commit 58c8bd1

Please sign in to comment.