From cf0334d5d18681d41fa1d67376510ad679910481 Mon Sep 17 00:00:00 2001 From: Saikat Sarkar Date: Fri, 10 Jan 2025 12:49:02 -0700 Subject: [PATCH] Update the content of view code --- .../__snapshots__/py_lang_client.test.tsx.snap | 11 ++++++----- .../components/view_code/examples/py_lang_client.tsx | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/__snapshots__/py_lang_client.test.tsx.snap b/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/__snapshots__/py_lang_client.test.tsx.snap index 0001f45600ec2..00950530db5ed 100644 --- a/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/__snapshots__/py_lang_client.test.tsx.snap +++ b/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/__snapshots__/py_lang_client.test.tsx.snap @@ -40,11 +40,12 @@ def get_elasticsearch_results(): def create_openai_prompt(results): context = \\"\\" for hit in results: - inner_hit_path = f\\"{hit['_index']}.{index_source_fields.get(hit['_index'])[0]}\\" - - ## For semantic_text matches, we need to extract the text from the inner_hits - if 'inner_hits' in hit and inner_hit_path in hit['inner_hits']: - context += '\\\\n --- \\\\n'.join(inner_hit['_source']['text'] for inner_hit in hit['inner_hits'][inner_hit_path]['hits']['hits']) + ## For semantic_text matches, we need to extract the text from the highlighted field + if "highlight" in hit: + highlighted_texts = [] + for values in hit["highlight"].values(): + highlighted_texts.extend(values) + context += "\\\\n --- \\\\n".join(highlighted_texts) else: source_field = index_source_fields.get(hit[\\"_index\\"])[0] hit_context = hit[\\"_source\\"][source_field] diff --git a/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/py_lang_client.tsx b/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/py_lang_client.tsx index a2d92583c6b63..746ecd293ad5e 100644 --- a/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/py_lang_client.tsx +++ b/x-pack/solutions/search/plugins/search_playground/public/components/view_code/examples/py_lang_client.tsx @@ -40,11 +40,12 @@ def get_elasticsearch_results(): def create_openai_prompt(results): context = "" for hit in results: - inner_hit_path = f"{hit['_index']}.{index_source_fields.get(hit['_index'])[0]}" - - ## For semantic_text matches, we need to extract the text from the inner_hits - if 'inner_hits' in hit and inner_hit_path in hit['inner_hits']: - context += '\\n --- \\n'.join(inner_hit['_source']['text'] for inner_hit in hit['inner_hits'][inner_hit_path]['hits']['hits']) + ## For semantic_text matches, we need to extract the text from the highlighted field + if "highlight" in hit: + highlighted_texts = [] + for values in hit["highlight"].values(): + highlighted_texts.extend(values) + context += "\\n --- \\n".join(highlighted_texts) else: source_field = index_source_fields.get(hit["_index"])[0] hit_context = hit["_source"][source_field]