-
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.
Merge pull request #227 from nulib/deploy/staging
Deploy v2.4.1 to Production
- Loading branch information
Showing
25 changed files
with
258 additions
and
173 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
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
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
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,60 @@ | ||
# dc-api-v2 chatbot | ||
|
||
[![Build Status](https://github.com/nulib/dc-api-v2/actions/workflows/test-python.yml/badge.svg)](https://github.com/nulib/dc-api-v2/actions/workflows/test-python.yml) | ||
|
||
## Local development setup | ||
|
||
##### ⚠️ *All commands and instructions in this file assume that the current working directory is the `/chat` subdirectory of the `dc-api-v2` project.* | ||
|
||
### Link `samconfig.yaml` | ||
|
||
This only needs to be done once. | ||
|
||
1. Pull the `miscellany` repo. | ||
2. Link the development `samconfig.yaml` file | ||
```bash | ||
ln -s /path/to/miscellany/dc-api-v2/chat/samconfig.yaml . | ||
``` | ||
|
||
### Deploy a development stack | ||
|
||
1. [Log into AWS](http://docs.rdc.library.northwestern.edu/2._Developer_Guides/Environment_and_Tools/AWS-Authentication/) using your `staging-admin` profile. | ||
2. Pick a unique stack name, e.g., `dc-api-chat-[YOUR_INITIALS]` | ||
3. Create or synchronize the development stack | ||
```bash | ||
sam sync --watch --config-env dev --stack-name [STACK_NAME] | ||
``` | ||
|
||
The first time the `sam sync` command is run, it will build the development stack. This takes longer than it will on subsequent runs. | ||
|
||
While the `sam sync` remains open, it will keep the development stack synchronized with any code changes you make. Each time you change a file, you'll need to wait for the output of that command to indicate that resource syncing is finished. | ||
|
||
The first time the stack is created, it will show you the stack's outputs, including the websocket URL to use for interacting with the chat backend, e.g.: | ||
``` | ||
------------------------------------------------------------------------------------------------- | ||
CloudFormation outputs from deployed stack | ||
------------------------------------------------------------------------------------------------- | ||
Outputs | ||
------------------------------------------------------------------------------------------------- | ||
Key WebSocketURI | ||
Description The WSS Protocol URI to connect to | ||
Value wss://nmom3hnp3c.execute-api.us-east-1.amazonaws.com/latest | ||
------------------------------------------------------------------------------------------------- | ||
``` | ||
|
||
On subsequent sync runs, the outputs will not be displayed. If you need to retrieve the value again, you can run | ||
```bash | ||
sam list stack-outputs --stack-name [STACK_NAME] | ||
``` | ||
|
||
To stop synchronizing changes, simply terminate the `sam sync` process with `Ctrl+C`. | ||
|
||
### Tear down the development stack | ||
|
||
The development stack will remain up and active even after `sam sync` exits; it will simply not actively synchronize changes any more. To tear it down completely, you have to delete it yourself. | ||
|
||
1. [Log into AWS](http://docs.rdc.library.northwestern.edu/2._Developer_Guides/Environment_and_Tools/AWS-Authentication/) using your `staging-admin` profile. | ||
2. Delete the development stack | ||
```bash | ||
sam delete --stack-name [STACK_NAME] | ||
``` |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
boto3~=1.34.13 | ||
boto3~=1.34 | ||
honeybadger | ||
langchain | ||
langchain-community | ||
openai~=0.27.8 | ||
langchain~=0.2 | ||
langchain-aws~=0.1 | ||
langchain-openai~=0.1 | ||
openai~=1.35 | ||
opensearch-py | ||
pyjwt~=2.6.0 | ||
python-dotenv~=1.0.0 | ||
requests | ||
requests-aws4auth | ||
tiktoken~=0.4.0 | ||
wheel~=0.40.0 | ||
tiktoken~=0.7 | ||
wheel~=0.40 |
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
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
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 |
---|---|---|
@@ -1,11 +1,22 @@ | ||
from langchain.callbacks.base import BaseCallbackHandler | ||
from websocket import Websocket | ||
from typing import Any | ||
from langchain_core.outputs.llm_result import LLMResult | ||
|
||
class StreamingSocketCallbackHandler(BaseCallbackHandler): | ||
def __init__(self, socket: Websocket, debug_mode: bool): | ||
def __init__(self, socket: Websocket, stream: bool = True): | ||
self.socket = socket | ||
self.debug_mode = debug_mode | ||
self.stream = stream | ||
|
||
def on_llm_new_token(self, token: str, **kwargs): | ||
if self.socket and not self.debug_mode: | ||
if len(token) > 0 and self.socket and self.stream: | ||
return self.socket.send({"token": token}) | ||
|
||
def on_llm_end(self, response: LLMResult, **kwargs: Any): | ||
try: | ||
finish_reason = response.generations[0][0].generation_info["finish_reason"] | ||
if self.socket: | ||
return self.socket.send({"end": {"reason": finish_reason}}) | ||
except Exception as err: | ||
finish_reason = f'Unknown ({str(err)})' | ||
print(f"Stream ended: {finish_reason}") |
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
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
Oops, something went wrong.