Skip to content

Commit

Permalink
Migrate from LangChainJS to LangChain Python (#90)
Browse files Browse the repository at this point in the history
* Introduce the langchain-api package

* Migrate chains from TS to Python

* Remove unused files

* Update API docs
  • Loading branch information
homanp authored May 1, 2023
1 parent b7405d7 commit 8987dde
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 171 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Features:
- [x] Bring your own Auth provider
- [x] Chatbots
- [x] Prompt templates
- [ ] API endpoints to chatbot
- [-] API endpoints to chatbot
- [ ] External datasources
- [ ] chatGPT plugins
- [ ] Chatbots themes
Expand All @@ -60,6 +60,14 @@ LangChain UI utilizes NextJS 13 `appDir`. Read more about it [here](https://next

## Getting started

### Langchain UI API

We have migrated all agent functionality from LangChain Typescript to LangChain Python. Thus you will need to run the (Langchain UI API)[https://github.com/homanp/langchain-ui] in order to interact with the chatbot. In the future when the TS package is on par with the Python package we will migrate to only using Javascript.

### Getting started

1. Setup the (Langchain UI API)[https://github.com/homanp/langchain-ui]

1. Clone the repo into a public GitHub repository (or fork https://github.com/homanp/langchain-ui/fork). If you plan to distribute the code, keep the source code public.

```sh
Expand Down
69 changes: 0 additions & 69 deletions app/api/v1/chatbots/[chatbotId]/route.js

This file was deleted.

4 changes: 3 additions & 1 deletion components/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { createChatbotMessage } from "@/lib/api";
import ChatInput from "./input";
import ChatOuput from "./output";

const API_URL = process.env.NEXT_PUBLIC_LANGCHAIN_UI_API_URL;

export default function Chat({ id, ...properties }) {
const [messages, setMessages] = useState([]);
const [newMessage, setNewMessage] = useState();
Expand All @@ -27,7 +29,7 @@ export default function Chat({ id, ...properties }) {
agent: "user",
});

await fetchEventSource(`/api/v1/chatbots/${id}`, {
await fetchEventSource(`${API_URL}chatbots/${id}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
3 changes: 2 additions & 1 deletion env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ METAL_INDEX_ID=""
METAL_CLIENT_ID=""
NEXT_PUBLIC_AMAZON_S3_BUCKET_NAME=""
NEXT_PUBLIC_AMAZON_S3_SECRET_ACCESS_KEY=""
NEXT_PUBLIC_AMAZON_S3_ACCESS_KEY_ID=""
NEXT_PUBLIC_AMAZON_S3_ACCESS_KEY_ID=""
NEXT_PUBLIC_LANGCHAIN_UI_API_URL=""
8 changes: 4 additions & 4 deletions lib/api-docs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cURL = `\`\`\`bash
# cURL request to chatbot API endpoint.
curl -X POST https://langchain-ui.vercel.app/api/v1/chatbot/{{id}}
curl -X POST https://dolphin-app-tmpol.ondigitalocean.app/api/v1/chatbot/{{id}}
-H "Content-Type: application/json"
-H "Authorization: Bearer {token}"
-d '{"message": "Hello!"}'
Expand All @@ -18,7 +18,7 @@ const requestOptions = {
};
const response = await fetch(
'https://langchain-ui.vercel.app/api/v1/chatbot/{{id}}',
'https://dolphin-app-tmpol.ondigitalocean.app/api/v1/chatbot/{{id}}',
requestOptions
);
const data = await response.json();
Expand All @@ -28,7 +28,7 @@ const python = `\`\`\`python
# Python request to chatbot API endpoint using the requests library.
import requests
url = 'https://langchain-ui.vercel.app/api/v1/chatbot/{{id}}'
url = 'https://dolphin-app-tmpol.ondigitalocean.app/api/v1/chatbot/{{id}}'
headers = {'Authorization': 'Bearer {token}'}
payload = {'messsage': 'Hello!'}
Expand All @@ -40,7 +40,7 @@ print(response.text)
const php = `\`\`\`php
# PHP request to chatbot API endpoint.
<?php
$url = "https://langchain-ui.vercel.app/api/v1/chatbot/{{id}}";
$url = "https://dolphin-app-tmpol.ondigitalocean.app/api/v1/chatbot/{{id}}";
$data = array(
"messate" => "Hello!"
);
Expand Down
78 changes: 0 additions & 78 deletions lib/chain.js

This file was deleted.

17 changes: 0 additions & 17 deletions lib/prompt-template.js

This file was deleted.

1 comment on commit 8987dde

@vercel
Copy link

@vercel vercel bot commented on 8987dde May 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

langchain-ui – ./

langchain-ui-git-main-homanp.vercel.app
langchain-ui-homanp.vercel.app
langchain-ui.vercel.app

Please sign in to comment.