mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Add error handling for 401 status in Copilot; refactor JsonRequest and response classes for improved structure and clarity
This commit is contained in:
parent
1fb8b7e4c9
commit
a55256a4c3
2 changed files with 7 additions and 6 deletions
|
|
@ -167,6 +167,8 @@ class Copilot(AsyncAuthedProvider, ProviderModelMixin):
|
|||
},
|
||||
json=data
|
||||
)
|
||||
if response.status_code == 401:
|
||||
raise MissingAuthError("Status 401: Invalid session")
|
||||
response.raise_for_status()
|
||||
conversation = Conversation(response.json().get("currentConversationId"))
|
||||
debug.log(f"Copilot: Created conversation: {conversation.conversation_id}")
|
||||
|
|
|
|||
|
|
@ -174,15 +174,14 @@ class JsonResponse(ResponseType, ObjectMixin):
|
|||
def __str__(self) -> str:
|
||||
return str(self.get_dict())
|
||||
|
||||
class JsonRequest(ResponseType, ObjectMixin):
|
||||
def __str__(self) -> str:
|
||||
return str(self.get_dict())
|
||||
|
||||
class HiddenResponse(ResponseType):
|
||||
def __str__(self) -> str:
|
||||
"""Hidden responses return an empty string."""
|
||||
return ""
|
||||
|
||||
class JsonRequest(HiddenResponse, ObjectMixin):
|
||||
pass
|
||||
|
||||
class FinishReason(JsonMixin, HiddenResponse):
|
||||
def __init__(self, reason: str) -> None:
|
||||
"""Initialize with a reason."""
|
||||
|
|
@ -425,7 +424,7 @@ class VideoResponse(MediaResponse):
|
|||
return "\n".join(result)
|
||||
return "\n".join([f'<video src="{quote_url(video)}"></video>' for video in self.get_list()])
|
||||
|
||||
class ImagePreview(ImageResponse, HiddenResponse):
|
||||
class ImagePreview(HiddenResponse, ImageResponse):
|
||||
pass
|
||||
|
||||
class PreviewResponse(HiddenResponse):
|
||||
|
|
@ -442,5 +441,5 @@ class Parameters(ResponseType, JsonMixin):
|
|||
"""Return an empty string."""
|
||||
return ""
|
||||
|
||||
class ProviderInfo(JsonMixin, HiddenResponse):
|
||||
class ProviderInfo(HiddenResponse, JsonMixin):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue