Skip to content

Commit

Permalink
fix gemini issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CTY-git committed Feb 13, 2025
1 parent 9ae98c7 commit 7a7d4bc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions patchwork/common/client/llm/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def is_prompt_supported(
model=model,
contents=chat,
config=CountTokensConfig(
system_instructions=system,
system_instruction=system,
),
)
token_count = token_response.total_tokens
Expand Down Expand Up @@ -181,15 +181,15 @@ def chat_completion(
config=GenerateContentConfig(
system_instruction=system_content,
safety_settings=self.__SAFETY_SETTINGS,
**generation_dict,
**NotGiven.remove_not_given(generation_dict),
),
)
return self.__google_response_to_openai_response(response, model)

@staticmethod
def __google_response_to_openai_response(google_response: GenerateContentResponse, model: str) -> ChatCompletion:
choices = []
for candidate in google_response.candidates:
for index, candidate in enumerate(google_response.candidates):
# note that instead of system, from openai, its model, from google.
parts = [part.text or part.inline_data for part in candidate.content.parts]

Expand All @@ -202,7 +202,7 @@ def __google_response_to_openai_response(google_response: GenerateContentRespons

choice = Choice(
finish_reason=finish_reason_map.get(candidate.finish_reason, "stop"),
index=candidate.index,
index=index,
message=ChatCompletionMessage(
content="\n".join(parts),
role="assistant",
Expand Down
12 changes: 8 additions & 4 deletions patchwork/steps/ReadEmail/ReadEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
from patchwork.step import Step
from patchwork.steps.ReadEmail.typed import ReadEmailInputs, ReadEmailOutputs


class InnerParsedHeader(BaseModel):
message_id: list[str] = Field(alias="message-id")


class ParsedHeader(BaseModel):
subject: str = ""
from_: str = Field(alias="from", default_factory=str)
Expand Down Expand Up @@ -91,10 +93,12 @@ def run(self) -> dict:
for content_transfer_encoding in attachment.content_header.content_transfer_encoding:
content = self.__decode(content_transfer_encoding, content)
f.write(content)
rv["attachments"].append(dict(
path=str(file_path),
# content=content.decode(),
))
rv["attachments"].append(
dict(
path=str(file_path),
# content=content.decode(),
)
)

for body in email_data.body:
rv["body"] += body.content
Expand Down
4 changes: 2 additions & 2 deletions patchwork/steps/SendEmail/SendEmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def run(self) -> dict:
msg["From"] = self.sender_email
msg["To"] = self.recipient_email
if self.reply_message_id is not None:
msg.add_header('Reference', self.reply_message_id)
msg.add_header('In-Reply-To', self.reply_message_id)
msg.add_header("Reference", self.reply_message_id)
msg.add_header("In-Reply-To", self.reply_message_id)

# TODO: support smtp without ssl
with smtplib.SMTP_SSL(self.smtp_host, self.smtp_port) as smtp_server:
Expand Down
1 change: 1 addition & 0 deletions patchwork/steps/SimplifiedLLMOnce/typed.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SimplifiedLLMOnceInputs(__SimplifiedLLMOncePBInputsRequired, total=False):
google_api_key: Annotated[
str, StepTypeConfig(is_config=True, or_op=["patched_api_key", "openai_api_key", "anthropic_api_key"])
]
file: Annotated[str, StepTypeConfig(is_path=True)]


class SimplifiedLLMOnceOutputs(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "patchwork-cli"
version = "0.0.99.dev2"
version = "0.0.99.dev3"
description = ""
authors = ["patched.codes"]
license = "AGPL"
Expand Down

0 comments on commit 7a7d4bc

Please sign in to comment.