Getting None respone from ChatOllama in tagging exercise #25840
Replies: 1 comment
-
Hey there, @uzairlatif90! I'm here to help you with any issues you're facing. I'm a bot designed to assist you with bug fixes, answer your questions, and guide you on becoming a contributor. Let's tackle this challenge together! 🤖 To determine the cause of a
Here is a code snippet that highlights the key areas to check: def _generate(
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
run_manager: Optional[CallbackManagerForLLMRun] = None,
**kwargs: Any,
) -> ChatResult:
functions = kwargs.get("functions", [])
if "functions" in kwargs:
del kwargs["functions"]
if "function_call" in kwargs:
functions = [
fn for fn in functions if fn["name"] == kwargs["function_call"]["name"]
]
if not functions:
raise ValueError(
"If `function_call` is specified, you must also pass a "
"matching function in `functions`."
)
del kwargs["function_call"]
functions = [convert_to_ollama_tool(fn) for fn in functions]
functions.append(DEFAULT_RESPONSE_FUNCTION)
system_message_prompt_template = SystemMessagePromptTemplate.from_template(
self.tool_system_prompt_template
)
system_message = system_message_prompt_template.format(
tools=json.dumps(functions, indent=2)
)
response_message = super()._generate(
[system_message] + messages, stop=stop, run_manager=run_manager, **kwargs
)
chat_generation_content = response_message.generations[0].text
if not isinstance(chat_generation_content, str):
raise ValueError("OllamaFunctions does not support non-string output.")
try:
parsed_chat_result = json.loads(chat_generation_content)
except json.JSONDecodeError:
raise ValueError(
f"""'{self.model}' did not respond with valid JSON.
Please try again.
Response: {chat_generation_content}"""
)
called_tool_name = (
parsed_chat_result["tool"] if "tool" in parsed_chat_result else None
)
called_tool = next(
(fn for fn in functions if fn["name"] == called_tool_name), None
)
if (
called_tool is None
or called_tool["name"] == DEFAULT_RESPONSE_FUNCTION["name"]
):
if (
"tool_input" in parsed_chat_result
and "response" in parsed_chat_result["tool_input"]
):
response = parsed_chat_result["tool_input"]["response"]
elif "response" in parsed_chat_result:
response = parsed_chat_result["response"]
else:
raise ValueError(
f"Failed to parse a response from {self.model} output: "
f"{chat_generation_content}"
)
return ChatResult(
generations=[
ChatGeneration(
message=AIMessage(
content=response,
)
)
]
) By following these steps and checking the relevant parts of the code, you should be able to identify and correct the cause of a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I am trying to use Langchain with ChatOllama to tag customer conversation wtih different tags based on a Classification schema. When I invoke the chain, sometimes I get a proper response from the LLM but somtimes I get a None response from the chain without any explanation of what might have caused it. How can I know what is causing a None respone and how can I correct for that?
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
Beta Was this translation helpful? Give feedback.
All reactions