This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from openchatai/feat/summarizer
Adding a summarization column to be used when summarizing responses
- Loading branch information
Showing
10 changed files
with
161 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
from typing import List, Optional | ||
from typing import List | ||
from langchain.pydantic_v1 import BaseModel, Field | ||
from langchain.output_parsers import PydanticOutputParser | ||
|
||
|
||
class BotMessage(BaseModel): | ||
bot_message: str = Field(description="Message from the bot") | ||
ids: List[str] = Field(description="List of IDs") | ||
missing_information: Optional[str] = Field(description="Incase of ambiguity ask user follow up question") | ||
|
||
|
||
|
||
|
||
# Set up a parser + inject instructions into the prompt template. | ||
bot_message_parser = PydanticOutputParser(pydantic_object=BotMessage) | ||
|
||
|
||
# bot_message_parser.parse(input_string) | ||
def parse_bot_message(input: str) -> BotMessage: | ||
return bot_message_parser.parse(input) | ||
return bot_message_parser.parse(input) |
41 changes: 41 additions & 0 deletions
41
llm-server/models/migrations/versions/d845330c4432_add_system_summary_prompt_to_chatbot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Add system_summary_prompt to Chatbot | ||
Revision ID: d845330c4432 | ||
Revises: 86c78095b920 | ||
Create Date: 2023-12-12 14:35:53.182454 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "d845330c4432" | ||
down_revision: Union[str, None] = "86c78095b920" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade(): | ||
if ( | ||
not op.get_bind() | ||
.execute(sa.text("SHOW COLUMNS FROM chatbots LIKE 'summary_prompt'")) | ||
.fetchone() | ||
): | ||
op.add_column("chatbots", sa.Column("summary_prompt", sa.Text(), nullable=True)) | ||
|
||
op.execute( | ||
""" | ||
UPDATE chatbots | ||
SET summary_prompt = "Given a JSON response, summarize the key information in a concise manner. Include relevant details, references, and links if present. Format the summary in Markdown for clarity and readability." | ||
""" | ||
) | ||
|
||
op.alter_column( | ||
"chatbots", "summary_prompt", existing_type=sa.TEXT(), nullable=False | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column("chatbots", "system_summary_prompt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.