Skip to content

Commit

Permalink
chore: Configure coverage.io and update ci.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Sep 27, 2024
1 parent 97609d3 commit 7d5a860
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ jobs:
poetry run ruff format --check
poetry build
- name: Run tests
run: poetry run pytest
run: poetry run pytest --cov --cov-report=xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
COZE_TOKEN: ${{ secrets.COZE_TOKEN }}
SPACE_ID_1: ${{ secrets.SPACE_ID_1 }}
COZE_JWT_AUTH_CLIENT_ID: ${{ secrets.COZE_JWT_AUTH_CLIENT_ID }}
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ And then install dependencies:
poetry install
```

Run the code

## Pre Commit

```shell
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pip install cozepy

## Usage

### Examples

TODO

### Auth

#### Personal Auth Token
Expand Down Expand Up @@ -83,7 +87,7 @@ chat_iterator = coze.chat.stream(
)
for event in chat_iterator:
if event.event == ChatEventType.conversation_message_delta:
print('got message delta:', event.messages.content)
print('got message delta:', event.message.content)
```

### Bots
Expand Down
1 change: 1 addition & 0 deletions cozepy/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class TokenAuth(Auth):
"""

def __init__(self, token: str):
# TODO: 其他 sdk 实现
assert isinstance(token, str)
assert len(token) > 0
self._token = token
Expand Down
10 changes: 5 additions & 5 deletions cozepy/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from enum import Enum
from typing import Dict, List, Iterator, Union, TYPE_CHECKING, Optional

Expand Down Expand Up @@ -184,6 +183,9 @@ class Chat(CozeModel):
# Details of the information needed for execution.


# TODO: 枚举值是否需要大写


class ChatEventType(str, Enum):
# Event for creating a conversation, indicating the start of the conversation.
# 创建对话的事件,表示对话开始。
Expand Down Expand Up @@ -268,17 +270,15 @@ def __next__(self) -> ChatEvent:
ChatEventType.conversation_message_delta,
ChatEventType.conversation_message_completed,
]:
return ChatEvent(
event=event, message=Message.model_validate(json.loads(data))
)
return ChatEvent(event=event, message=Message.model_validate_json(data))
elif event in [
ChatEventType.conversation_chat_created,
ChatEventType.conversation_chat_in_progress,
ChatEventType.conversation_chat_completed,
ChatEventType.conversation_chat_failed,
ChatEventType.conversation_chat_requires_action,
]:
return ChatEvent(event=event, chat=Chat.model_validate(json.loads(data)))
return ChatEvent(event=event, chat=Chat.model_validate_json(data))
else:
raise ValueError(f"invalid chat.event: {event}, {data}")

Expand Down
95 changes: 94 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typing-extensions = "^4.3.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
pytest-cov = "^4.0.0"
ruff = "^0.6.0"
pre-commit = "^2.9.0"

Expand Down

0 comments on commit 7d5a860

Please sign in to comment.