-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,863 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# PlugBear Python SDK Example (LangChain) | ||
|
||
This project introduces an example of integrating a LangServe application with | ||
communication channels, such as Slack, using PlugBear. Check the [PlugBear Docs: LangServe](https://docs.plugbear.io/integrations/langchain/langserve) page to learn more. | ||
|
||
## Prerequisites | ||
|
||
- [Poetry](https://python-poetry.org) | ||
|
||
## Development | ||
|
||
### Installing Dependencies | ||
|
||
Use [Poetry](https://python-poetry.org/) to install dependencies. | ||
|
||
```bash | ||
poetry install | ||
``` | ||
|
||
### Running Server | ||
|
||
Run the command below to run the server: | ||
|
||
```bash | ||
OPENAI_API_KEY="YOUR_OPENAI_API_KEY" \ | ||
PLUGBEAR_API_KEY="YOUR_PLUGBEAR_API_KEY" \ | ||
poetry run python main.py | ||
``` | ||
|
||
You can obtain your `OPENAI_API_KEY` from the | ||
[OpenAI API Keys](https://platform.openai.com/api-keys) page and your | ||
`PLUGBEAR_API_KEY` from the | ||
[PlugBear API Keys](https://auth.plugbear.io/org/api_keys) page. | ||
|
||
### Testing Integration | ||
|
||
Follow [PlugBear Documentation](https://docs.plugbear.io) to connect your app | ||
to communication channels and test it. | ||
|
||
Ask any math question to `@PlugBear` after connecting it. e.g., | ||
``@PlugBear This is an example sentence.``. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from operator import itemgetter | ||
|
||
from fastapi import FastAPI | ||
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder | ||
from langchain_core.messages import convert_to_messages | ||
from langchain_core.output_parsers import StrOutputParser | ||
from langchain_openai import ChatOpenAI | ||
from langserve import add_routes | ||
|
||
import plugbear.fastapi | ||
|
||
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"] | ||
PLUGBEAR_API_KEY = os.environ["PLUGBEAR_API_KEY"] | ||
|
||
app = FastAPI() | ||
llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY) | ||
output_parser = StrOutputParser() | ||
prompt = ChatPromptTemplate.from_messages( | ||
[ | ||
("system", "You are the Proofreading Bot, an editor bot designed to proofread technical manuals with the precision and style of a professional technical writer. Your primary function is to make the text clear, concise, and professional. You avoid jargon, ambiguous expressions, and emotional language, aiming for straightforward, easy-to-understand, yet professional sentences. You specialize in improving the readability and accuracy of technical manuals, adhering to high standards of technical writing. While maintaining professionalism, your interaction style is helpful, providing guidance and suggestions to enhance the user's text. Answer the revised version of the text only. Do not add any other descriptions."), | ||
MessagesPlaceholder("conversation"), | ||
] | ||
) | ||
runnable = {"conversation": convert_to_messages} | prompt | llm | output_parser | ||
|
||
add_routes( | ||
app, | ||
runnable, | ||
path="/proofreading-bot-langserve", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
|
||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", default=8000))) |
Oops, something went wrong.