-
Notifications
You must be signed in to change notification settings - Fork 0
chore: sync workflow templates #124
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
Changes from all commits
28c21b2
41bc21c
b12bf9d
47cb2eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -987,22 +987,76 @@ def _invoke_llm( | |
| issue_number: int | None, | ||
| ) -> str: | ||
| """Invoke LLM and return response text.""" | ||
| from langchain_core.messages import HumanMessage | ||
| try: | ||
| from langchain_core import messages as langchain_messages | ||
| except ModuleNotFoundError: | ||
| human_message_cls = None | ||
| else: | ||
| human_message_cls = getattr(langchain_messages, "HumanMessage", None) | ||
|
|
||
| config = _build_llm_config( | ||
| operation=operation, | ||
| pr_number=pr_number, | ||
| issue_number=issue_number, | ||
| ) | ||
|
|
||
| def normalize_response_content(response: Any) -> str: | ||
| content = getattr(response, "content", None) | ||
| if content is None: | ||
| return str(response) | ||
| if isinstance(content, str): | ||
| return content | ||
| if isinstance(content, list): | ||
| parts: list[str] = [] | ||
| for item in content: | ||
| if isinstance(item, str): | ||
| parts.append(item) | ||
| elif isinstance(item, dict): | ||
| text_value = item.get("text") | ||
| if isinstance(text_value, str): | ||
| parts.append(text_value) | ||
| continue | ||
| content_value = item.get("content") | ||
| if isinstance(content_value, str): | ||
| parts.append(content_value) | ||
| continue | ||
| parts.append(json.dumps(item, ensure_ascii=False, sort_keys=True)) | ||
| else: | ||
| parts.append(str(item)) | ||
| combined = "".join(parts).strip() | ||
| return combined or str(content) | ||
| if isinstance(content, dict): | ||
| return json.dumps(content, ensure_ascii=False, sort_keys=True) | ||
| return str(content) | ||
|
|
||
| if human_message_cls is not None: | ||
| messages: list[Any] = [human_message_cls(content=prompt)] | ||
| try: | ||
| response = client.invoke(messages, config=config) | ||
| except TypeError as exc: | ||
| LOGGER.warning( | ||
| "LLM invoke failed with config/metadata; using config/metadata fallback. Error: %s", | ||
| exc, | ||
| ) | ||
| response = client.invoke(messages) | ||
|
Comment on lines
+1037
to
+1041
|
||
| return normalize_response_content(response) | ||
|
|
||
| # langchain_core isn't available. Prefer non-message invoke signatures first. | ||
| try: | ||
| response = client.invoke([HumanMessage(content=prompt)], config=config) | ||
| response = client.invoke(prompt, config=config) | ||
| except TypeError as exc: | ||
| LOGGER.warning( | ||
| "LLM invoke failed with config/metadata; using config/metadata fallback. Error: %s", | ||
| exc, | ||
| ) | ||
|
Comment on lines
1048
to
1051
|
||
| response = client.invoke([HumanMessage(content=prompt)]) | ||
| return response.content | ||
| try: | ||
| response = client.invoke(prompt) | ||
| except Exception as inner_exc: | ||
| raise RuntimeError( | ||
| "Unable to invoke client without langchain_core installed. " | ||
| "Install langchain-core or provide a client that accepts plain string prompts." | ||
| ) from inner_exc | ||
| return normalize_response_content(response) | ||
|
|
||
|
|
||
| def _extract_json(text: str) -> dict[str, Any]: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Joining
partswith an empty separator can merge adjacent chunks and change meaning (e.g.,["Hello", "world"]becomes"Helloworld"). Consider joining with a separator that preserves boundaries (commonly"\n"or" ") or implementing a boundary-preserving join strategy for mixed chunk types.