-
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.
Limit the maximum length of the chat response
- Add language to prompt to encourage concise answers - Limit responses to 1000 tokens by default, with `max_tokens` superuser override - Add `{"end": {"reason": reason}}` message - Update chat/response to use latest langchain and LCEL - Turn streaming on or off independent of debug mode - Split runtime and dev dependencies into separate `requirements.txt` files to keep the `sam sync` layer size below 10MB - Update `chat/template.yml` and `Makefile` to support rapid iterations without separate dependency layer Co-Authored-By: Brendan Quinn <[email protected]>
- Loading branch information
Showing
15 changed files
with
182 additions
and
140 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
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
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,3 @@ | ||
# Dev/Test Dependencies | ||
ruff~=0.1.0 | ||
coverage~=7.3.2 |
Oops, something went wrong.