Replies: 2 comments 26 replies
-
Hey @depshad! I'm here to help you with any bugs, questions, or contributions you have. Let's solve this together! To skip the usage of def _call(
self,
inputs: Dict[str, Any],
run_manager: Optional[CallbackManagerForChainRun] = None,
) -> Dict[str, str]:
_run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
intermediate_steps = {}
instructions = inputs[self.instructions_key]
instructions = instructions[: self.max_text_length]
# Directly deserialize the JSON input without using predict_and_parse
api_arguments = json.dumps(inputs)
intermediate_steps["request_args"] = api_arguments
_run_manager.on_text(
api_arguments, color="green", end="\n", verbose=self.verbose
)
if api_arguments.startswith("ERROR"):
return self._get_output(api_arguments, intermediate_steps)
elif api_arguments.startswith("MESSAGE:"):
return self._get_output(
api_arguments[len("MESSAGE:") :], intermediate_steps
)
try:
request_args = self.deserialize_json_input(api_arguments)
method = getattr(self.requests, self.api_operation.method.value)
api_response: Response = method(**request_args)
if api_response.status_code != 200:
method_str = str(self.api_operation.method.value)
response_text = (
f"{api_response.status_code}: {api_response.reason}"
+ f"\nFor {method_str.upper()} {request_args['url']}\n"
+ f"Called with args: {request_args['params']}"
)
else:
response_text = api_response.text
except Exception as e:
response_text = f"Error with message {str(e)}"
response_text = response_text[: self.max_text_length]
intermediate_steps["response_text"] = response_text
_run_manager.on_text(
response_text, color="blue", end="\n", verbose=self.verbose
)
if self.api_response_chain is not None:
_answer = self.api_response_chain.predict_and_parse(
response=response_text,
instructions=instructions,
callbacks=_run_manager.get_child(),
)
answer = cast(str, _answer)
_run_manager.on_text(answer, color="yellow", end="\n", verbose=self.verbose)
return self._get_output(answer, intermediate_steps)
else:
return self._get_output(response_text, intermediate_steps) This modification ensures that the JSON payload is directly deserialized and used without being altered by the |
Beta Was this translation helpful? Give feedback.
-
@dosu how can I convert structured tool to Openai function? Is there a need to do so for openai function calling? |
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
JSON payload from OpenAI is altered by the APIRequesterChain. Specifically predict_and_parse method. How can we skip the usage of predict_and_parse in
System Info
langchain==0.2.12
langchain-community==0.2.11
langchain-core==0.2.29
langchain-openai==0.1.20
langchain-text-splitters==0.2.2
platform: mac
python: 3.10.2
Beta Was this translation helpful? Give feedback.
All reactions