Skip to content

Commit

Permalink
add ci test
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Sep 24, 2024
1 parent 94bea80 commit b694a89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
COZE_JWT_AUTH_CLIENT_ID: ${{ secrets.COZE_JWT_AUTH_CLIENT_ID }}
COZE_JWT_AUTH_PRIVATE_KEY: ${{ secrets.COZE_JWT_AUTH_PRIVATE_KEY }}
COZE_JWT_AUTH_KEY_ID: ${{ secrets.COZE_JWT_AUTH_KEY_ID }}
COZE_BOT_ID_TRANSLATE: ${{ secrets.COZE_BOT_ID_TRANSLATE }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

Expand Down
4 changes: 2 additions & 2 deletions cozepy/chat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from enum import Enum
from typing import Dict, List, Iterator, Tuple
from typing import Dict, List, Iterator, Tuple, Union

from .auth import Auth
from .model import Message, Chat, MessageResponse, CozeModel
Expand Down Expand Up @@ -118,7 +118,7 @@ def chat_v3(
auto_save_history: bool = True,
meta_data: Dict[str, str] = None,
conversation_id: str = None,
) -> Tuple[Chat, ChatIterator]:
) -> Union[Chat, ChatIterator]:
"""
Create a conversation.
Conversation is an interaction between a bot and a user, including one or more messages.
Expand Down
4 changes: 2 additions & 2 deletions cozepy/request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Tuple, Optional, Iterator
from typing import TYPE_CHECKING, Tuple, Optional, Iterator, Union

import requests
from requests import Response
Expand Down Expand Up @@ -37,7 +37,7 @@ def request(
headers: dict = None,
body: dict = None,
stream: bool = False,
) -> Tuple[T, Iterator[bytes]]:
) -> Union[T, Iterator[bytes]]:
"""
Send a request to the server.
"""
Expand Down
41 changes: 41 additions & 0 deletions tests/test_chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os

from cozepy import TokenAuth, Coze, COZE_CN_BASE_URL, Message, ChatIterator, Event
from cozepy.auth import _random_hex


def test_chat_v3_not_stream():
token = os.getenv("COZE_TOKEN").strip()
bot_id = os.getenv("COZE_BOT_ID_TRANSLATE").strip()

auth = TokenAuth(token)
cli = Coze(auth=auth, base_url=COZE_CN_BASE_URL)

chat = cli.chat.chat_v3(
bot_id=bot_id,
user_id=_random_hex(10),
additional_messages=[Message.user_text_message("Hi, how are you?")],
stream=False,
)
assert chat is not None
assert chat.id != ""


def test_chat_v3_stream():
token = os.getenv("COZE_TOKEN").strip()
bot_id = os.getenv("COZE_BOT_ID_TRANSLATE").strip()

auth = TokenAuth(token)
cli = Coze(auth=auth, base_url=COZE_CN_BASE_URL)

chat_iter: ChatIterator = cli.chat.chat_v3(
bot_id=bot_id,
user_id=_random_hex(10),
additional_messages=[Message.user_text_message("Hi, how are you?")],
stream=True,
)
for item in chat_iter:
assert item is not None
assert item.event != ""
if item.event == Event.conversation_message_delta:
assert item.message.content != ""

0 comments on commit b694a89

Please sign in to comment.