Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fix mypy #67

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plexar/core/gradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ async def generate(
chat_history=history,
generate_config=generate_config,
)

chunk: Optional["ChatCompletionChunk"] = None
async for chunk in chat_generator:
assert chunk is not None
delta = chunk["choices"][0]["delta"]
if "content" not in delta:
continue
Expand Down
17 changes: 9 additions & 8 deletions plexar/model/llm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ def _to_prompt(
):
ret = system_prompt
for message in chat_history:
role_name, content = message
ret += f"{self._sep}{role_name}: {content}"
role = message["role"]
content = message["content"]
ret += f"{self._sep}{role}: {content}"
ret += f"{self._sep}{self._user_name}: {prompt}"
ret += f"{self._sep}{self._assistant_name}:"
return ret
Expand Down Expand Up @@ -278,10 +279,10 @@ def chat(
stream = generate_config["stream"]

if stream:
return self._convert_chat_completion_chunks_to_chat(
self.generate(full_prompt, generate_config)
)
it = self.generate(full_prompt, generate_config)
assert isinstance(it, Iterator)
return self._convert_chat_completion_chunks_to_chat(it)
else:
return self._convert_text_completion_to_chat(
self.generate(full_prompt, generate_config)
)
c = self.generate(full_prompt, generate_config)
assert not isinstance(c, Iterator)
return self._convert_text_completion_to_chat(c)