Trying to Create ReACT Agent using Mistral LLM using HuggingFace Inference API but getting error
HuggingFaceAPI
import os
from getpass import getpass
from huggingface_hub import login
HuggingFace API
HF_TOKEN = getpass()
login(token=HF_TOKEN)
Loading LLM endpoint
from llama_index.llms.huggingface import HuggingFaceInferenceAPI
llm = HuggingFaceInferenceAPI(model_name="mistralai/Mistral-7B-Instruct-v0.2", token=HF_TOKEN, num_output=512, is_function_calling_model=True, is_chat_model=True)
Simple Calculator
from llama_index.core.agent import ReActAgent
from llama_index.core.llms import ChatMessage
from llama_index.core.tools import BaseTool, FunctionTool
Define Tool
def multiply(a: int, b: int) -> int:
"""Multiply two integers and returns the result integer"""
return a * b
def add(a: int, b: int) -> int:
"""Add two integers and returns the result integer"""
return a + b
def subtract(a: int, b: int) -> int:
"""Subtract two integers and returns the result integer"""
return a - b
multiply_tool = FunctionTool.from_defaults(fn=multiply)
add_tool = FunctionTool.from_defaults(fn=add)
subtract_tool = FunctionTool.from_defaults(fn=subtract)
Mistral
agent = ReActAgent.from_tools([multiply_tool, add_tool, subtract_tool], llm=llm, verbose=True)
response = agent.chat("What is 20+(2*4)? Calculate step by step.")
Error -
NotImplementedError: Messages passed in must be of odd length. Add a reply
Sign up and join the conversation on Discord