(history: list[dict], tools: list[dict], role_name_replace: dict = None)
| 35 | |
| 36 | |
| 37 | def process_input(history: list[dict], tools: list[dict], role_name_replace: dict = None) -> list[dict]: |
| 38 | chat_history = [] |
| 39 | # if len(tools) > 0: |
| 40 | chat_history.append({"role": "system", "content": build_system_prompt(list(ALL_TOOLS), tools)}) |
| 41 | |
| 42 | for conversation in history: |
| 43 | role = str(conversation.role).removeprefix("<|").removesuffix("|>") |
| 44 | if role_name_replace: |
| 45 | role = role_name_replace.get(role, role) |
| 46 | item = { |
| 47 | "role": role, |
| 48 | "content": conversation.content, |
| 49 | } |
| 50 | if conversation.metadata: |
| 51 | item["metadata"] = conversation.metadata |
| 52 | # Only append image for user |
| 53 | if role == "user" and conversation.image: |
| 54 | item["image"] = conversation.image |
| 55 | chat_history.append(item) |
| 56 | |
| 57 | return chat_history |
| 58 | |
| 59 | |
| 60 | def process_response(output, history): |
no test coverage detected