(poster_input, questions, answers, aspects, input_type, agent_config)
| 805 | return Image.open(io.BytesIO(new_raw)) |
| 806 | |
| 807 | def eval_qa_get_answer(poster_input, questions, answers, aspects, input_type, agent_config): |
| 808 | agent_name = f'answer_question_from_{input_type}' |
| 809 | with open(f"utils/prompt_templates/{agent_name}.yaml", "r") as f: |
| 810 | config = yaml.safe_load(f) |
| 811 | |
| 812 | if agent_config['model_platform'].is_vllm: |
| 813 | actor_model = ModelFactory.create( |
| 814 | model_platform=agent_config['model_platform'], |
| 815 | model_type=agent_config['model_type'], |
| 816 | model_config_dict=agent_config['model_config'], |
| 817 | url=agent_config['url'], |
| 818 | ) |
| 819 | else: |
| 820 | actor_model = ModelFactory.create( |
| 821 | model_platform=agent_config['model_platform'], |
| 822 | model_type=agent_config['model_type'], |
| 823 | model_config_dict=agent_config['model_config'], |
| 824 | ) |
| 825 | |
| 826 | actor_sys_msg = config['system_prompt'] |
| 827 | |
| 828 | actor_agent = ChatAgent( |
| 829 | system_message=actor_sys_msg, |
| 830 | model=actor_model, |
| 831 | message_window_size=None, |
| 832 | ) |
| 833 | |
| 834 | actor_agent.reset() |
| 835 | |
| 836 | jinja_env = Environment(undefined=StrictUndefined) |
| 837 | |
| 838 | template = jinja_env.from_string(config["template"]) |
| 839 | |
| 840 | if input_type == 'text': |
| 841 | prompt = template.render(**{ |
| 842 | 'questions': questions, |
| 843 | 'poster_text': poster_input, |
| 844 | }) |
| 845 | response = actor_agent.step(prompt) |
| 846 | agent_answers = get_json_from_response(response.msgs[0].content) |
| 847 | elif input_type == 'image': |
| 848 | if 'max_images' in agent_config: |
| 849 | max_images = agent_config['max_images'] |
| 850 | else: |
| 851 | max_images = len(poster_input) |
| 852 | prompt = template.render(**{ |
| 853 | 'questions': questions, |
| 854 | }) |
| 855 | msg = BaseMessage.make_user_message( |
| 856 | role_name="User", |
| 857 | content=prompt, |
| 858 | image_list=poster_input[:max_images], |
| 859 | ) |
| 860 | response = actor_agent.step(msg) |
| 861 | agent_answers = get_json_from_response(response.msgs[0].content) |
| 862 | |
| 863 | input_token, output_token = account_token(response) |
| 864 |
no test coverage detected