From 21769c8ad9740619f272c3cdf7eb73e719bb7459 Mon Sep 17 00:00:00 2001
From: clean99 <xff9924@gmail.com>
Date: Wed, 5 Feb 2025 12:28:32 +0800
Subject: [PATCH] Fix: update deprecated response property in examples (#1614)

Co-authored-by: Marcus Schiesser <mail@marcusschiesser.de>
---
 .changeset/neat-masks-smell.md           | 5 +++++
 examples/agent/query_openai_agent.ts     | 4 ++--
 examples/agent/retriever_openai_agent.ts | 4 ++--
 examples/anthropic/agent.ts              | 4 ++--
 examples/groq.ts                         | 4 ++--
 examples/rerankers/CohereReranker.ts     | 8 ++++----
 examples/vectorIndex.ts                  | 4 ++--
 examples/vectorIndexCustomize.ts         | 4 ++--
 8 files changed, 21 insertions(+), 16 deletions(-)
 create mode 100644 .changeset/neat-masks-smell.md

diff --git a/.changeset/neat-masks-smell.md b/.changeset/neat-masks-smell.md
new file mode 100644
index 000000000..5dcfea80d
--- /dev/null
+++ b/.changeset/neat-masks-smell.md
@@ -0,0 +1,5 @@
+---
+"@llamaindex/examples": minor
+---
+
+Update deprecated response property of query engine to message.content propery
diff --git a/examples/agent/query_openai_agent.ts b/examples/agent/query_openai_agent.ts
index 57dc838f5..dc8b63b9f 100644
--- a/examples/agent/query_openai_agent.ts
+++ b/examples/agent/query_openai_agent.ts
@@ -33,12 +33,12 @@ async function main() {
   });
 
   // Chat with the agent
-  const response = await agent.chat({
+  const { message } = await agent.chat({
     message: "What was his first salary?",
   });
 
   // Print the response
-  console.log(response.response);
+  console.log(message.content);
 }
 
 void main().then(() => {
diff --git a/examples/agent/retriever_openai_agent.ts b/examples/agent/retriever_openai_agent.ts
index 09e940951..e9e5d84aa 100644
--- a/examples/agent/retriever_openai_agent.ts
+++ b/examples/agent/retriever_openai_agent.ts
@@ -52,12 +52,12 @@ async function main() {
   });
 
   // Chat with the agent
-  const response = await agent.chat({
+  const { message } = await agent.chat({
     message: "What was his first salary?",
   });
 
   // Print the response
-  console.log(response.response);
+  console.log(message.content);
 }
 
 void main().then(() => {
diff --git a/examples/anthropic/agent.ts b/examples/anthropic/agent.ts
index 5e5a64951..8892dc40e 100644
--- a/examples/anthropic/agent.ts
+++ b/examples/anthropic/agent.ts
@@ -38,12 +38,12 @@ const agent = new AnthropicAgent({
 });
 
 async function main() {
-  const { response } = await agent.chat({
+  const { message } = await agent.chat({
     message:
       "What is the weather in New York? What's the history of New York from Wikipedia in 3 sentences?",
   });
 
-  console.log(response);
+  console.log(message.content);
 }
 
 void main();
diff --git a/examples/groq.ts b/examples/groq.ts
index 624c1c7b8..1c7b4b9af 100644
--- a/examples/groq.ts
+++ b/examples/groq.ts
@@ -38,12 +38,12 @@ async function main() {
   const query = "What is the meaning of life?";
 
   // Query
-  const response = await queryEngine.query({
+  const { message } = await queryEngine.query({
     query,
   });
 
   // Log the response
-  console.log(response.response);
+  console.log(message.content);
 }
 
 main().catch(console.error);
diff --git a/examples/rerankers/CohereReranker.ts b/examples/rerankers/CohereReranker.ts
index c838d54d7..6b4bda87b 100644
--- a/examples/rerankers/CohereReranker.ts
+++ b/examples/rerankers/CohereReranker.ts
@@ -33,19 +33,19 @@ async function main() {
     retriever,
   });
 
-  const response = await queryEngine.query({
+  const { message } = await queryEngine.query({
     query: "What did the author do growing up?",
   });
 
   // cohere response
-  console.log(response.response);
+  console.log(message.content);
 
-  const baseResponse = await baseQueryEngine.query({
+  const { message: baseMessage } = await baseQueryEngine.query({
     query: "What did the author do growing up?",
   });
 
   // response without cohere
-  console.log(baseResponse.response);
+  console.log(baseMessage.content);
 }
 
 main().catch(console.error);
diff --git a/examples/vectorIndex.ts b/examples/vectorIndex.ts
index b5403788f..f0cc50232 100644
--- a/examples/vectorIndex.ts
+++ b/examples/vectorIndex.ts
@@ -21,12 +21,12 @@ async function main() {
 
   // Query the index
   const queryEngine = index.asQueryEngine();
-  const { response, sourceNodes } = await queryEngine.query({
+  const { message, sourceNodes } = await queryEngine.query({
     query: "What did the author do in college?",
   });
 
   // Output response with sources
-  console.log(response);
+  console.log(message.content);
 
   if (sourceNodes) {
     sourceNodes.forEach((source: NodeWithScore, index: number) => {
diff --git a/examples/vectorIndexCustomize.ts b/examples/vectorIndexCustomize.ts
index 9f04c7048..437a5415b 100644
--- a/examples/vectorIndexCustomize.ts
+++ b/examples/vectorIndexCustomize.ts
@@ -29,10 +29,10 @@ async function main() {
     nodePostprocessor,
   ]);
 
-  const response = await queryEngine.query({
+  const { message } = await queryEngine.query({
     query: "What did the author do growing up?",
   });
-  console.log(response.response);
+  console.log(message.content);
 }
 
 main().catch(console.error);
-- 
GitLab