New paste Repaste Download
openai_ainvoke_mock = <AsyncMock name='ainvoke' id='2578182902528'>, open_ai_mock = <MagicMock name='invoke' id='2578181233136'>
open_ai_agen_with_fallback_mock = <MagicMock name='with_fallbacks' id='2578181232848'>, client = <FlaskClient <Flask 'app'>>, is_redraft = True
mock_response_key = 'non_hallucinated'
tokens = {'access_token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTcxNTY3OTIzMCwianRpIjoiMDg2NTg3NWI...3dqVVpUU2pVcWhfMjJPQ2JwaHVJT2RDVmpVNjJQd01LaGtLU3V0M2VCZjhiZW8xN3NnPT0ifQ.-8-dnLlEJaEvkPRocwS8viUGB1-XIITgO0eRPhSNSuQ'}
work_flow_cache = {'contract_type': '916e19c9e3e942e2822b0d9335266339', 'conversation_ids': {'CaseSummary': '93c90640-ea67-4d6b-ae39-c8c...e': 'Confidentiality', 'create_time': 1715679234, 'create_uid': '568486cef5a44647956c39edfcea3d92', ...}, ...]}}}, ...}
    @pytest.mark.parametrize(
        "is_redraft,mock_response_key",
        [
            (True, "non_hallucinated"),
            (False, "non_hallucinated"),
            (True, "hallucinated"),
            (False, "hallucinated"),
        ],
    )
    @mock.patch("utils.LLM.model.ChatOpenAI.with_fallbacks")
    @mock.patch("utils.LLM.model.ChatOpenAI.invoke")
    @mock.patch("utils.LLM.model.ChatOpenAI.ainvoke")
    def test_redraft_remediation(
            openai_ainvoke_mock,
            open_ai_mock,
            open_ai_agen_with_fallback_mock,
            client: FlaskClient,
            is_redraft: bool,
            mock_response_key: str,
            tokens: Dict[str, str],
            work_flow_cache,
    ):
        token = tokens["access_token"]
        with open(
                Path(__file__).parent / "test_data/test_langchain_data.json",
                encoding="utf-8"
        ) as lang_fp:
            openai_sample = json.load(lang_fp)
            mock_open_ai = mock.MagicMock(name="__call__").return_value
            ai_common_response = json.dumps(openai_sample["redraft"][mock_response_key])
            mock_open_ai.content = ai_common_response
            open_ai_mock.return_value = mock_open_ai
    
            conversation_id = "751e1a88-5a53-4162-8b91-be6c06b66935"
            project_id = work_flow_cache["projects"]["Document Redraft"]
            doc_id = work_flow_cache["doc_ids"]["Document Redraft"][0]
            function_id = work_flow_cache["functions"]["redline"]["platform"]["function_id"]
    
            def mock_with_fallbacks(self, **kwargs):
                return self[0]
    
            open_ai_agen_with_fallback_mock.side_effect = mock_with_fallbacks
            openai_ainvoke_mock.return_value = mock.MagicMock(
                "Response",
                content=ai_common_response,
            )
            result = client.post(
                path="/v1/stream_redraft_remediation",
                json={
                    "project_id": project_id,
                    "doc_id": doc_id,
                    "chat_model": {
                        "query": "Generate Redraft Recommendations",
                        "action": "ReDraftContract",
                        "conversation_id": conversation_id,
                    },
                    "dynamic_field": "ContractPodAi",
                    "is_redraft": is_redraft,
                    "function_id": function_id,
                },
                headers={"Authorization": f"Bearer {token}"},
            )
>           assert result.status_code == 200
E           assert 500 == 200
E            +  where 500 = <WrapperTestResponse streamed [500 INTERNAL SERVER ERROR]>.status_code
tests\test_26_stream_redraft_remediation.py:171: AssertionError
Filename: None. Size: 4kb. View raw, , hex, or download this file.

This paste expires on 2024-05-21 09:36:42.906860. Pasted through deprecated-web.