gemini-1.5-pro
on ChatGoogleGenerativeAI
generates a newline token in every response
#24648
Replies: 2 comments
-
Hey @tanmaygupta9! I'm here to help you out with any bugs, questions, or contributions you may have. Let's get to the bottom of this together! To prevent def _generate(
self,
prompts: List[str],
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> LLMResult:
generations: List[List[Generation]] = []
generation_config = {
"stop_sequences": stop,
"temperature": self.temperature,
"top_p": self.top_p,
"top_k": self.top_k,
"max_output_tokens": self.max_output_tokens,
"candidate_count": self.n,
}
for prompt in prompts:
if self.is_gemini:
res = completion_with_retry(
self,
prompt=prompt,
stream=False,
is_gemini=True,
run_manager=run_manager,
generation_config=generation_config,
)
candidates = [
"".join([p.text for p in c.content.parts]).rstrip("\n") for c in res.candidates
]
generations.append([Generation(text=c) for c in candidates])
else:
res = completion_with_retry(
self,
model=self.model_name,
prompt=prompt,
stream=False,
is_gemini=False,
run_manager=run_manager,
**generation_config,
)
prompt_generations = []
for candidate in res.candidates:
raw_text = candidate["output"]
stripped_text = _strip_erroneous_leading_spaces(raw_text).rstrip("\n")
prompt_generations.append(Generation(text=stripped_text))
generations.append(prompt_generations)
return LLMResult(generations=generations) In this modification, the |
Beta Was this translation helpful? Give feedback.
-
I created PR 598 for this issue. |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I'm trying to use
gemini-1.5-pro
for a task, accessed through Langchain's wrapperChatGoogleGenerativeAI
, and each of its responses has a trailing " \n" character in it. This seems to be the behavior only for Gemini 1.5 Pro because Gemini 1.0 does not do this.This is important for my use case because I'm asking Gemini to produce a key for a dictionary, but it produces the key with a trailing " \n" which makes my code break.
I can obviously just post-process the output but I'm trying to see if there's a cleaner solution to fix this at the generation step itself because I want my app to be LLM-neutral.
System Info
System Information
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found:
Beta Was this translation helpful? Give feedback.
All reactions