Skip to content

Commit

Permalink
update repo with ts branch
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul007-bit committed Jan 28, 2024
2 parents 33f5c94 + 0c6b23f commit c83f892
Show file tree
Hide file tree
Showing 21 changed files with 948 additions and 772 deletions.
89 changes: 45 additions & 44 deletions JS/edgechains/examples/react-chain/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@


```markdown
````markdown
# ReactChain

## Introduction

ReactChain is a library for integrating OpenAI's GPT-3 with a custom template for natural language processing tasks. It utilizes Node.js, Hono, and other dependencies for seamless integration.

## Features
- **GPT-3 Integration:** Easily make calls to OpenAI's GPT-3 endpoint using a custom template.
- **Template Customization:** Define custom templates for various natural language processing scenarios.
- **Web Server Integration:** Use Hono to handle incoming HTTP requests with ease.

- **GPT-3 Integration:** Easily make calls to OpenAI's GPT-3 endpoint using a custom template.
- **Template Customization:** Define custom templates for various natural language processing scenarios.
- **Web Server Integration:** Use Hono to handle incoming HTTP requests with ease.

## Installation

1. Clone the repository:
```bash
git clone https://github.com/your-username/ReactChain.git
cd ReactChain
```
```bash
git clone https://github.com/your-username/ReactChain.git
cd ReactChain
```
````

2. Install dependencies:
```bash
npm install
```

```bash
npm install
```

3. Set up environment variables:
Create a `.env` file in the root directory and add the following:
```env
OPENAI_API_KEY=your-openai-api-key
```
```env
OPENAI_API_KEY=your-openai-api-key
```

## Usage



### How to run ReActChain:-

- Use the following command in the root directory to run this example:
Expand All @@ -47,53 +48,52 @@ ReactChain is a library for integrating OpenAI's GPT-3 with a custom template fo
- import UserInput("") and invoked and pass a query as argument string:
`{"UserInput("")": "Your Search Topic"}`



1. Customize Templates:
- Edit `react-chain.jsonnet` to customize GPT-3 prompts.
- Edit `intermediate.jsonnet` for specific use cases.

- Edit `react-chain.jsonnet` to customize GPT-3 prompts.
- Edit `intermediate.jsonnet` for specific use cases.

## Scripts
- **Build:** Remove the `dist` directory and build the project.
```bash
npm run build
```

- **Build:** Remove the `dist` directory and build the project.



- **Test:** Run Jest tests.
```bash
npm run test
```
```bash
npm run build
```

- **Test:** Run Jest tests.
```bash
npm run test
```

2. Run the Development Server:
```bash
npm run start
```

```bash
npm run start
```

3. Make API Calls:
- Make HTTP requests to `http://localhost:3000/` with the desired query.
- Make HTTP requests to `http://localhost:3000/` with the desired query.

## Dependencies
- @hono/node-server
- @types/dotenv
- hono
- pg
- reflect-metadata
- tsc
- typescript

- @hono/node-server
- @types/dotenv
- hono
- pg
- reflect-metadata
- tsc
- typescript

## Contributing

1. Fork the repository.
2. Create a new branch: `git checkout -b feature/new-feature`.
3. Make your changes and commit them: `git commit -m 'Add new feature'`.
4. Push to the branch: `git push origin feature/new-feature`.
5. Submit a pull request.

## License

This project is licensed under the ISC License - see the [LICENSE.md](LICENSE.md) file for details.

```
Expand All @@ -102,3 +102,4 @@ This project is licensed under the ISC License - see the [LICENSE.md](LICENSE.md



```
17 changes: 8 additions & 9 deletions JS/edgechains/examples/react-chain/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
preset: "ts-jest",
testEnvironment: "node",
transform: {
'^.+\\.tsx?$': 'ts-jest',
"^.+\\.tsx?$": "ts-jest",
},
extensionsToTreatAsEsm: ['.ts'],
extensionsToTreatAsEsm: [".ts"],
globals: {
'ts-jest': {
useESM: true,
},
"ts-jest": {
useESM: true,
},
},
};

};
1 change: 0 additions & 1 deletion JS/edgechains/examples/react-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "1.0.0",
"description": "",
"main": "dist/index.js",

"scripts": {
"build": "rm -rf dist && node esbuild.build.js",
"start": "node dist/index.js",
Expand Down
19 changes: 6 additions & 13 deletions JS/edgechains/examples/react-chain/src/ReactChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Jsonnet } from "@hanazuki/node-jsonnet";
import { OpenAiEndpoint } from "@arakoodev/edgechains.js";
import * as path from "path";
import { Hono } from "hono";
import dotenv from "dotenv"
import dotenv from "dotenv";

// Load environment variables from a .env file
dotenv.config();
Expand Down Expand Up @@ -33,7 +33,8 @@ export async function reactChainCall(query: string) {
const promptTemplate = JSON.parse(promptLoader).custom_template;

// Load and parse the intermediate template, injecting the prompt template and query
let InterLoader = await jsonnet.extString("promptTemplate", promptTemplate)
let InterLoader = await jsonnet
.extString("promptTemplate", promptTemplate)
.extString("query", query)
.evaluateFile(InterPath);

Expand All @@ -42,10 +43,8 @@ export async function reactChainCall(query: string) {
// Make a GPT-3 call using the OpenAiEndpoint
const gptResponse = await gpt3Endpoint.gptFn(prompt);


// Return the response
return gptResponse;

} catch (error) {
// Log and rethrow any errors that occur during the process
console.error(error);
Expand All @@ -62,11 +61,8 @@ export function UserInput(query: string) {
// Call the reactChainCall function with the provided query
const ReactChainCall = await reactChainCall(query);



// Respond with the ReactChainCall response
return res.json({ answer: ReactChainCall });

} catch (error) {
// If an error occurs, respond with an error status and message
return res.json({ error: "An error occurred" }, 500);
Expand All @@ -75,11 +71,8 @@ export function UserInput(query: string) {
}

// Example usage: Make a UserInput call with a specific query
UserInput("Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?");




UserInput(
"Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?"
);

// let query="Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?"

5 changes: 0 additions & 5 deletions JS/edgechains/examples/react-chain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { ReactChainRouter } from "./ReactChain.js";


const app = new Hono();



app.route("/", ReactChainRouter);



serve(app, () => {
console.log("server running on port 3000");
});
4 changes: 2 additions & 2 deletions JS/edgechains/examples/react-chain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"jsxImportSource": "hono/jsx",
"noImplicitAny": false,
"moduleResolution": "NodeNext",
"declaration": true
"declaration": true,
},
"include": ["src/**/*.ts", "dist/**/*.d.ts", "src/jest.config.js"]
"include": ["src/**/*.ts", "dist/**/*.d.ts", "src/jest.config.js"],
}
Loading

0 comments on commit c83f892

Please sign in to comment.