Skip to content

Commit

Permalink
add finish_reason to copilot output
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Apr 24, 2024
1 parent bbf0bb6 commit 92cea72
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
18 changes: 18 additions & 0 deletions bots/migrations/0067_alter_botintegration_user_language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-04-24 13:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bots', '0066_workflowmetadata_price_multiplier'),
]

operations = [
migrations.AlterField(
model_name='botintegration',
name='user_language',
field=models.TextField(blank=True, default='', help_text='The response language (same as user language in video bots)'),
),
]
3 changes: 2 additions & 1 deletion bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,9 @@ class BotIntegration(models.Model):
db_index=True,
)
user_language = models.TextField(
default="en",
default="",
help_text="The response language (same as user language in video bots)",
blank=True,
)
show_feedback_buttons = models.BooleanField(
default=False,
Expand Down
2 changes: 1 addition & 1 deletion daras_ai_v2/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def _process_and_send_msg(
# if no text, send the run status as text
update_msg_id = bot.send_run_status(update_msg_id=update_msg_id)
continue # no text, wait for the next update
streaming_done = bot.run_status.lower().startswith("completed")
streaming_done = state.get("finish_reason")
# send the response to the user
if bot.can_update_message:
update_msg_id = bot.send_msg(
Expand Down
9 changes: 5 additions & 4 deletions daras_ai_v2/facebook_bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,16 @@ def send_msg_to(

if audio and not video: # video already has audio
# simple audio msg
messages.append(
messages.insert(
0,
{
"type": "audio",
"audio": {"link": audio},
}
},
)

if documents:
messages += [
messages = [
# simple document msg
{
"type": "document",
Expand All @@ -238,7 +239,7 @@ def send_msg_to(
},
}
for link in documents
]
] + messages

return send_wa_msgs_raw(
bot_number=bot_number,
Expand Down
8 changes: 5 additions & 3 deletions recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ class ResponseModel(BaseModel):
output_documents: list[str] | None
reply_buttons: list[ReplyButton] | None

finish_reason: list[str] | None

def preview_image(self, state: dict) -> str | None:
return DEFAULT_COPILOT_META_IMG

Expand Down Expand Up @@ -1002,13 +1004,13 @@ def run_v2(
if asr_msg:
output_text = [asr_msg + "\n\n" + text for text in output_text]
response.output_text = output_text
if all(entry.get("finish_reason") for entry in entries):
finish_reasons = [entry.get("finish_reason") for entry in entries]
if all(finish_reasons):
if all_refs_list:
apply_response_formattings_suffix(
all_refs_list, response.output_text, citation_style
)
finish_reason = entries[0]["finish_reason"]
yield f"Completed with {finish_reason=}" # avoid changing this message since it's used to detect end of stream
response.finish_reason = finish_reasons
else:
yield f"Streaming{str(i + 1).translate(SUPERSCRIPT)} {model.value}..."

Expand Down

0 comments on commit 92cea72

Please sign in to comment.