Skip to content

Commit

Permalink
fix: new conversation update source_id
Browse files Browse the repository at this point in the history
  • Loading branch information
moeakwak committed Feb 3, 2024
1 parent ecb4047 commit e97a5a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions backend/api/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ async def reply(response: AskResponse):
create_time=current_time,
update_time=current_time
)
if use_team:
new_conv.source_id = config.openai_web.team_account_id
conversation = BaseConversation(**new_conv.model_dump(exclude_unset=True))
session.add(conversation)

Expand Down
26 changes: 12 additions & 14 deletions backend/api/sources/openai_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import uuid
from mimetypes import guess_type
from typing import AsyncGenerator

import websockets
import base64
Expand All @@ -11,10 +10,11 @@
import httpx
from fastapi.encoders import jsonable_encoder
import aiohttp
from httpx import AsyncClient
from pydantic import ValidationError

from api.conf import Config, Credentials
from api.enums import OpenaiWebChatModels, ChatSourceTypes
from api.enums import OpenaiWebChatModels
from api.exceptions import InvalidParamsException, OpenaiWebException, ResourceNotFoundException
from api.file_provider import FileProvider
from api.models.doc import OpenaiWebChatMessageMetadata, OpenaiWebConversationHistoryDocument, \
Expand Down Expand Up @@ -229,7 +229,7 @@ async def _receive_from_websocket(wss_url):
class OpenaiWebChatManager(metaclass=SingletonMeta):
def __init__(self):
self.semaphore = asyncio.Semaphore(1)
self.session = None
self.session: AsyncClient | None = None
self.reset_session()

def is_busy(self):
Expand Down Expand Up @@ -306,7 +306,8 @@ async def clear_conversations(self, use_team: bool = False):
response = await self.session.patch(url, json={"is_visible": False}, headers=req_headers(use_team))
await _check_response(response)

async def complete(self, model: OpenaiWebChatModels, text_content: str, use_team: bool, conversation_id: uuid.UUID = None,
async def complete(self, model: OpenaiWebChatModels, text_content: str, use_team: bool,
conversation_id: uuid.UUID = None,
parent_message_id: uuid.UUID = None,
plugin_ids: list[str] = None,
attachments: list[OpenaiWebChatMessageMetadataAttachment] = None,
Expand Down Expand Up @@ -369,15 +370,12 @@ async def complete(self, model: OpenaiWebChatModels, text_content: str, use_team
completion_request["arkose_token"] = None
data_json = json.dumps(jsonable_encoder(completion_request))

async with self.session.stream(
method="POST",
url=f"{config.openai_web.chatgpt_base_url}conversation",
data=data_json,
timeout=timeout,
headers=req_headers(use_team) | {
"referer": "https://chat.openai.com/" + (f"c/{conversation_id}" if conversation_id else "")
}
) as response:
async with self.session.stream(method="POST", url=f"{config.openai_web.chatgpt_base_url}conversation",
data=data_json, timeout=timeout,
headers=req_headers(use_team) | {
"referer": "https://chat.openai.com/" + (
f"c/{conversation_id}" if conversation_id else "")
}) as response:
await _check_response(response)

async for line in response.aiter_lines():
Expand Down Expand Up @@ -428,7 +426,7 @@ async def generate_conversation_title(self, conversation_id: str, message_id: st
response = await self.session.post(
url,
json={"message_id": message_id},
hearders=req_headers(use_team)
headers=req_headers(use_team)
)
await _check_response(response)
result = response.json()
Expand Down

0 comments on commit e97a5a1

Please sign in to comment.