Skip to content

Commit

Permalink
Add gemini style
Browse files Browse the repository at this point in the history
  • Loading branch information
ultmaster committed Dec 19, 2023
1 parent 3343cd7 commit 52be46c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion coml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def _fix_context_from_any_context(
return context

def generate_code(
self, request: str, variable_descriptions: dict[str, str], codes: list[str],
self,
request: str,
variable_descriptions: dict[str, str],
codes: list[str],
num_shots: int | None = None,
style: str | None = None,
) -> GenerateContext:
fewshots = cached_generate_fewshots()
messages: list[BaseMessage] = [
Expand All @@ -128,6 +132,19 @@ def generate_code(
)
question, _ = render_generate_context(context)
messages.append(HumanMessage(content=question))

if style == "gemini":
# Gemini doesn't support system message.
if len(messages) > 1 and isinstance(messages[1], HumanMessage):
messages[1] = HumanMessage(
content=GENERATE_INSTRUCTION
+ "\n\n### Task begin ###\n\n"
+ messages[1].content
)
messages = messages[1:]
else:
messages[0] = HumanMessage(content=GENERATE_INSTRUCTION)

debug_messages(*messages)

response = self.llm(messages)
Expand Down

0 comments on commit 52be46c

Please sign in to comment.