Skip to content

Commit

Permalink
revise gemini api bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ShilinHe committed Dec 20, 2023
1 parent 6f8b82c commit 37cbbb4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 18 additions & 5 deletions taskweaver/llm/google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,29 @@ def _chat_completion(
**kwargs: Any,
) -> Generator[ChatMessageType, None, None]:
genai_messages = []
prev_role = ""
for msg in messages:
if msg["role"] == "system" or msg["role"] == "user":
if msg["role"] == "system":
genai_messages.append({"role": "user", "parts": [msg["content"]]})
genai_messages.append(
{
"role": "model",
"parts": ["I understand your requirements, and I will assist you in the conversations."],
},
)
prev_role = "model"
elif msg["role"] == "user":
if prev_role == "user":
# a placeholder to create alternating user and model messages
genai_messages.append({"role": "model", "parts": [" "]})
genai_messages.append({"role": "user", "parts": [msg["content"]]})
prev_role = "user"
elif msg["role"] == "assistant":
genai_messages.append({"role": "model", "parts": [msg["content"]]})
prev_role = "model"
else:
raise Exception(f"Invalid role: {msg['role']}")

genai_messages.insert(
1,
{"role": "model", "parts": ["I understand your requirements, and I will assist you in the conversations."]},
)
if stream is False:
response = self.model.generate_content(genai_messages, stream=False)
yield format_chat_message("assistant", response.text)
Expand Down
10 changes: 5 additions & 5 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const config = {
position: 'left',
label: 'Docs',
},
{to: '/blog', label: 'Blog', position: 'left'},
// {to: '/blog', label: 'Blog', position: 'left'},
{
href: 'https://github.com/microsoft/taskweaver/',
label: 'GitHub',
Expand Down Expand Up @@ -124,10 +124,10 @@ const config = {
{
title: 'More',
items: [
{
label: 'Blog',
to: '/blog',
},
// {
// label: 'Blog',
// to: '/blog',
// },
{
label: 'GitHub',
href: 'https://github.com/microsoft/taskweaver/',
Expand Down

0 comments on commit 37cbbb4

Please sign in to comment.