-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into table-redsign
- Loading branch information
Showing
58 changed files
with
1,622 additions
and
500 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
organization: arc53 | ||
defaultSticker: clqmdf0ed34290glbvqh0kzxd | ||
organization: docsgpt | ||
defaultSticker: cm1ulwkkl180570cl82rtzympu | ||
stickers: | ||
- id: clqmdf0ed34290glbvqh0kzxd | ||
alias: festive | ||
- id: cm1ulwkkl180570cl82rtzympu | ||
alias: contributor2024 | ||
- id: cm1ureg8o130450cl8c1po6mil | ||
alias: api | ||
- id: cm1urhmag148240cl8yvqxkthx | ||
alias: lpc | ||
- id: cm1urlcpq622090cl2tvu4w71y | ||
alias: lexeu |
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
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 |
---|---|---|
|
@@ -35,7 +35,8 @@ We're eager to provide personalized assistance when deploying your DocsGPT to a | |
|
||
[Send Email :email:](mailto:[email protected]?subject=DocsGPT%20support%2Fsolutions) | ||
|
||
![video-example-of-docs-gpt](https://d3dg1063dc54p9.cloudfront.net/videos/demov3.gif) | ||
|
||
<img src="https://github.com/user-attachments/assets/9a1f21de-7a15-4e42-9424-70d22ba5a913" alt="video-example-of-docs-gpt" width="1000" height="500"> | ||
|
||
## Roadmap | ||
|
||
|
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,93 @@ | ||
import redis | ||
import time | ||
import json | ||
import logging | ||
from threading import Lock | ||
from application.core.settings import settings | ||
from application.utils import get_hash | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_redis_instance = None | ||
_instance_lock = Lock() | ||
|
||
def get_redis_instance(): | ||
global _redis_instance | ||
if _redis_instance is None: | ||
with _instance_lock: | ||
if _redis_instance is None: | ||
try: | ||
_redis_instance = redis.Redis.from_url(settings.CACHE_REDIS_URL, socket_connect_timeout=2) | ||
except redis.ConnectionError as e: | ||
logger.error(f"Redis connection error: {e}") | ||
_redis_instance = None | ||
return _redis_instance | ||
|
||
def gen_cache_key(*messages, model="docgpt"): | ||
if not all(isinstance(msg, dict) for msg in messages): | ||
raise ValueError("All messages must be dictionaries.") | ||
messages_str = json.dumps(list(messages), sort_keys=True) | ||
combined = f"{model}_{messages_str}" | ||
cache_key = get_hash(combined) | ||
return cache_key | ||
|
||
def gen_cache(func): | ||
def wrapper(self, model, messages, *args, **kwargs): | ||
try: | ||
cache_key = gen_cache_key(*messages) | ||
redis_client = get_redis_instance() | ||
if redis_client: | ||
try: | ||
cached_response = redis_client.get(cache_key) | ||
if cached_response: | ||
return cached_response.decode('utf-8') | ||
except redis.ConnectionError as e: | ||
logger.error(f"Redis connection error: {e}") | ||
|
||
result = func(self, model, messages, *args, **kwargs) | ||
if redis_client: | ||
try: | ||
redis_client.set(cache_key, result, ex=1800) | ||
except redis.ConnectionError as e: | ||
logger.error(f"Redis connection error: {e}") | ||
|
||
return result | ||
except ValueError as e: | ||
logger.error(e) | ||
return "Error: No user message found in the conversation to generate a cache key." | ||
return wrapper | ||
|
||
def stream_cache(func): | ||
def wrapper(self, model, messages, stream, *args, **kwargs): | ||
cache_key = gen_cache_key(*messages) | ||
logger.info(f"Stream cache key: {cache_key}") | ||
|
||
redis_client = get_redis_instance() | ||
if redis_client: | ||
try: | ||
cached_response = redis_client.get(cache_key) | ||
if cached_response: | ||
logger.info(f"Cache hit for stream key: {cache_key}") | ||
cached_response = json.loads(cached_response.decode('utf-8')) | ||
for chunk in cached_response: | ||
yield chunk | ||
time.sleep(0.03) | ||
return | ||
except redis.ConnectionError as e: | ||
logger.error(f"Redis connection error: {e}") | ||
|
||
result = func(self, model, messages, stream, *args, **kwargs) | ||
stream_cache_data = [] | ||
|
||
for chunk in result: | ||
stream_cache_data.append(chunk) | ||
yield chunk | ||
|
||
if redis_client: | ||
try: | ||
redis_client.set(cache_key, json.dumps(stream_cache_data), ex=1800) | ||
logger.info(f"Stream cache saved for key: {cache_key}") | ||
except redis.ConnectionError as e: | ||
logger.error(f"Redis connection error: {e}") | ||
|
||
return wrapper |
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.