Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srikanth-kandi/mygenaichatbot
ChatBot with Open AI and LangChain
https://github.com/srikanth-kandi/mygenaichatbot
Last synced: 12 days ago
JSON representation
ChatBot with Open AI and LangChain
- Host: GitHub
- URL: https://github.com/srikanth-kandi/mygenaichatbot
- Owner: srikanth-kandi
- License: apache-2.0
- Created: 2023-07-30T12:20:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-04T06:56:32.000Z (over 1 year ago)
- Last Synced: 2024-12-15T10:08:32.030Z (2 months ago)
- Language: Jupyter Notebook
- Homepage: https://srigenai.ccbp.tech
- Size: 1.51 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ChatBot with OpenAI and LangChain
[Main Handbook](https://inky-ironclad-8d2.notion.site/Generative-AI-Workshop-bfb0123ccf6945ebbfa5bf3328917423), [This handbook](https://inky-ironclad-8d2.notion.site/ChatBot-with-Open-AI-and-LangChain-Handbook-36aee0b81838457e91a14c4ddf3378ce)
Prerequisites
- **Existing Open AI Account:**
- Check whether you have a limit to using the Open AI API
- The below screenshot indicated it is expired by June 1. So, you need to create a new account.

- Check your API key usage here
- **Creating Open AI Account with New Mail and New Phone Number:**
- Open https://openai.com
- Click on `Sign Up` button
- Choose your preffered Sign Up method
- After logged in click here to see below options

- **Create a Hugging Face Account**
- Open [https://huggingface.co/](https://huggingface.co/)- Click on `Sign Up` button
- Enter your details and Click on `Sign Up` button
- Verify your email address
- **Create a New Space in Hugging Face Account**
- Click on Profile icon top right
- Click on `New Space`
- Enter below details of your new space

- **Open the below provided Colab link**
- **Copying Code to your Google Drive**
- On the top left corner of Google Colab Notebook you can find `File`, click on it

- Click on `Save a copy in Drive`

- If you are not logged in to your Google Account, please log into it.- Once you are successfully logged in a new Google Colab Notebook with the given code will be opened
Install the required packages
- Click on the Play button to Install the Packages

Importing the required packages
- Click on the Play button to import the required things to build the application

Get the OpenAI API Key and set it as environmental variable
- Generate API Key
- Go to https://platform.openai.com/account/api-keys
- Click on `+ Create new secret key`
- Copy the Secret Key for your use
- Replace your `OPENAI_API_KEY` with your own API Key

- Click on the Play button

Assigning the values for template, prompt, and memory
- You can update the first line of the template with Prompts and Examples provided
- Click on the Play button

Initializing LLM Chain using OpenAI
- Using `ChatOpenAI` method we are creating an LLM Chain
- Click on the Play button

Define a function to generate the response for the question you ask
- From the initialized `llm_chain` we will predict the response
- Click on the Play button

Create a Chat Interface using Gradio
- We are creating the `ChatInterface` from gradio and providing a function `get_text_response` and also examples from Prompts and Examples provided
- Check for other arguments here
- Click on the Play button to create an interface

Launch your ChatBot with Gradio App
- Click on the Play button to launch the App

### Now you can try asking questions in your ChatBot
If you are getting any errors
- Keep print statements to identify the issue
- To identify the error you are getting please add `debug = True` while launching the gradio app
```python
if __name__ == "__main__":
demo.launch(debug = True)
``````python
def get_text_response(user_message,history):
try:
response = llm_chain.predict(user_message = user_message)
except Exception as e:
print("Error:", e)
try:
print("Error:", e.error.message)
response = "Failed to reply: " + e.error.message
except Exception as e:
response = "Failed to reply"
return response
```### Publish your code to Hugging Face
Login to Hugging Face from Google Colab
- Create a Hugging Face token and Copy
- Login to Hugging Face https://huggingface.co/
- Open https://huggingface.co/settings/tokens
- Click on `New token`
- Add a Name for the Token
- Choose `write` Role for the Token
- Click on `Generate a token`
- Copy the Token
- Click on Play button to enter Hugging Face Token

- Now paste the Hugging Face token in the textbox provided and click on `Login`

Create Hugging Face API to push code from Google Colab
- Click on the Play button to create API

Adding Hugging Face Repository ID
- Copy Hugging Face Repository ID by opening the Hugging Face Repo Created

- Replace your Repo ID

- Click on Play button to assign Hugging Face Repo ID

Add OPENAI_API_KEY in Hugging Face Repository secrets
- Click on Settings Button

- Go to `Variables and secrets` section

- Click on `New secret`

- Enter Name as `OPENAI_API_KEY` and Value as your OpenAI API Key

Load Application and Requirement files
- Click on the Play button to download files

- You can see downloaded files here

Editing the Application file
- Click on the `app.py` file

- The file will be opened and you can edit the `` and `` as per Prompts and Examples and save using `⌃ + S` or `⌘ + S`

Push your code to Hugging Face
- Click on Play button

- Now in your space, you should see it is `Building`

- On Succesful build, you should see `Running`

- If the Building fails, you will see a `Runtime error` with some errors below

- Click on Logs to check more details about the `error`
---
Show some ❤️ by starring ⭐ this repository!