From 4127a06c8f22e17e0bd2d77fe4f2b06b6bbc24c1 Mon Sep 17 00:00:00 2001 From: MSaifKhan01 Date: Tue, 23 Jan 2024 16:08:25 +0530 Subject: [PATCH] React-Chain-Code-Updated and Readme file Added --- .../react-chain/src/ReactChain.test.ts | 9 ++++++--- .../examples/react-chain/src/ReactChain.ts | 18 ++++++++---------- .../react-chain/src/react-chain.jsonnet | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/JS/edgechains/examples/react-chain/src/ReactChain.test.ts b/JS/edgechains/examples/react-chain/src/ReactChain.test.ts index 73bc7b4ba..1f9f7d6a2 100644 --- a/JS/edgechains/examples/react-chain/src/ReactChain.test.ts +++ b/JS/edgechains/examples/react-chain/src/ReactChain.test.ts @@ -1,7 +1,11 @@ -import { reactChainCall} from "./ReactChain"; -// const { reactChainCall } = require('./ReactChain'); +// Import the reactChainCall function from the ReactChain module +import { reactChainCall } from "./ReactChain"; + +// Describe block for the ReAct Chain test suite describe("ReAct Chain", () => { + // Test case: It should return a response it("should return a response", async () => { + // Call the reactChainCall function with a sample question const response = await reactChainCall( "Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?" ); @@ -10,4 +14,3 @@ describe("ReAct Chain", () => { expect(response).toContain("Bill Clinton"); }, 60000); // Increase the timeout to 60 seconds or as needed }); - diff --git a/JS/edgechains/examples/react-chain/src/ReactChain.ts b/JS/edgechains/examples/react-chain/src/ReactChain.ts index c91caadbf..992aff990 100644 --- a/JS/edgechains/examples/react-chain/src/ReactChain.ts +++ b/JS/edgechains/examples/react-chain/src/ReactChain.ts @@ -11,6 +11,7 @@ dotenv.config(); // Create instances of Jsonnet, Hono, and OpenAiEndpoint const jsonnet = new Jsonnet(); export const ReactChainRouter = new Hono(); + const gpt3Endpoint = new OpenAiEndpoint( "https://api.openai.com/v1/chat/completions", process.env.OPENAI_API_KEY!, @@ -41,11 +42,9 @@ export async function reactChainCall(query: string) { // Make a GPT-3 call using the OpenAiEndpoint const gptResponse = await gpt3Endpoint.gptFn(prompt); - // Replace escaped newline characters with actual newlines - const formattedResponse = gptResponse.replace(/\\n/g, '\n'); - - // Return the formatted response - return formattedResponse; + + // Return the response + return gptResponse; } catch (error) { // Log and rethrow any errors that occur during the process @@ -63,11 +62,10 @@ export function UserInput(query: string) { // Call the reactChainCall function with the provided query const ReactChainCall = await reactChainCall(query); - // Replace escaped newline characters with actual newlines in the response - const formattedResponse = ReactChainCall.replace(/\\n/g, '\n'); + - // Respond with the formatted answer - return res.json({ answer: formattedResponse }); + // Respond with the ReactChainCall response + return res.json({ answer: ReactChainCall }); } catch (error) { // If an error occurs, respond with an error status and message @@ -77,7 +75,7 @@ export function UserInput(query: string) { } // Example usage: Make a UserInput call with a specific query -UserInput("what is AI"); +UserInput("Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?"); diff --git a/JS/edgechains/examples/react-chain/src/react-chain.jsonnet b/JS/edgechains/examples/react-chain/src/react-chain.jsonnet index 1a601266d..d20aa837a 100644 --- a/JS/edgechains/examples/react-chain/src/react-chain.jsonnet +++ b/JS/edgechains/examples/react-chain/src/react-chain.jsonnet @@ -113,7 +113,7 @@ local CUSTOM_TEMPLATE = ||| and Leonid Levin have the same type of work. Action 3: Finish[yes] - Based upon the above prompt format, answer the user question in this format only. Doesn't stop in halfway.Give Full Response and give complete text + Based upon the above prompt format, answer the user question in this format only. Doesn't stop in halfway.each Thought , Action, Observation and Finish should be start from new line. Give Full Response and give complete text Question: {} |||;