Skip to content

Commit

Permalink
Merge pull request #231 from AugustLigh/August
Browse files Browse the repository at this point in the history
August
  • Loading branch information
Soulter authored Jun 6, 2024
2 parents 82b8e53 + def8fd2 commit 325776e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ conversation_list = chatbot.get_conversation_list()
# Get the available models (not hardcore)
models = chatbot.get_available_llm_models()

# Get image link.
# Work only for model "CohereForAI/c4ai-command-r-plus"
chat_result = chatbot.chat("Draw a cat.")
print(chat_result.get_final_text())
print(chat_result.get_image_link())

# Switch model with given index
chatbot.switch_llm(0) # Switch to the first model
chatbot.switch_llm(1) # Switch to the second model
Expand Down
7 changes: 7 additions & 0 deletions src/hugchat/hugchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ def _stream_query(
resp.encoding = 'utf-8'

if resp.status_code != 200:

retry_count -= 1
if retry_count <= 0:
raise exceptions.ChatError(
Expand All @@ -725,6 +726,12 @@ def _stream_query(
if obj.__contains__("type"):
_type = obj["type"]

if _type == "file":
_sha = obj["sha"]
_image_link = f"{self.hf_base_url}/chat/conversation/{conversation}/output/{_sha}"
yield {"type": _type, "image_link": _image_link}
continue

if _type == "finalAnswer":
final_answer = obj
break_flag = True
Expand Down
12 changes: 12 additions & 0 deletions src/hugchat/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
RESPONSE_TYPE_STREAM = "stream"
RESPONSE_TYPE_WEB = "webSearch"
RESPONSE_TYPE_STATUS = "status"
RESPONSE_TYPE_IMAGE = "file"
MSGTYPE_ERROR = "error"

MSGSTATUS_PENDING = 0
Expand Down Expand Up @@ -73,6 +74,7 @@ def __init__(
self.g = g
self._stream_yield_all = _stream_yield_all
self.web_search = web_search
self.image_link = None

@property
def text(self) -> str:
Expand Down Expand Up @@ -127,6 +129,9 @@ def __next__(self) -> dict:
self.web_search_done = True
elif t == RESPONSE_TYPE_STATUS:
pass
elif t == RESPONSE_TYPE_IMAGE:
if not a.__contains__("sha"):
self.image_link = a["image_link"]
else:
if "Model is overloaded" in str(a):
self.error = ModelOverloadedError(
Expand Down Expand Up @@ -185,6 +190,13 @@ def get_search_sources(self) -> list:
"""
return self.web_search_sources

def get_image_link(self) -> str:
"""
:Return:
- self.image_link
"""
return self.image_link

def search_enabled(self) -> bool:
"""
:Return:
Expand Down

0 comments on commit 325776e

Please sign in to comment.