Skip to content

Change return type from list[str] to list[dict]#238

Open
ZhengWentong wants to merge 3 commits into
GeeeekExplorer:mainfrom
ZhengWentong:ZhengWentong-patch-1
Open

Change return type from list[str] to list[dict]#238
ZhengWentong wants to merge 3 commits into
GeeeekExplorer:mainfrom
ZhengWentong:ZhengWentong-patch-1

Conversation

@ZhengWentong

Copy link
Copy Markdown

The function actually returns a list of dictionaries, but the type annotation was list[str]. This change aligns the annotation with the actual return value.

The function actually returns a list of dictionaries, but the type annotation was list[str]. This change aligns the annotation with the actual return value.
I noticed that the return type could potentially be made more precise as well.

Currently the function returns objects with a fixed structure:

```python
class GenerateOutput(TypedDict):
    text: str
    token_ids: list[int]

def generate(...) -> list[GenerateOutput]:
```

Using `TypedDict` may provide better type safety and IDE support compared with `list[dict]`. The current change focuses only on correcting the existing type annotation, but I thought this could be a useful improvement.
Add TypedDict for GenerateOutput in llm_engine.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant