BadRequestError: Error code: 400 - {'object': 'error', 'message': 'This model only supports single tool-calls at once!', 'type': 'BadRequestError', 'param': None, 'code': 400}
from llama_index.core.chat_engine import SimpleChatEngine from openai import OpenAI from llama_index.llms.openai_like import OpenAILike openai_api_key = "EMPTY" openai_api_base = "http://localhost:8000/v1" openai_client = OpenAI( api_key=openai_api_key, base_url=openai_api_base, ) models = openai_client.models.list() selected_model = models.data[0].id llm = OpenAILike( api_key=openai_api_key, api_base=openai_api_base, model=selected_model, max_tokens=2500, is_chat_model=True, ) chat_engine = SimpleChatEngine.from_defaults(llm=llm) chat_engine.chat("Hello")
from llama_index.core.llms import ChatMessage llm.chat([ChatMessage(role="user", content="Hello!")])
print(llm._get_model_kwargs())
openai
and llama-index-llms-openai
packagesfrom llama_index.core.llms import ChatMessage llm.chat([ChatMessage(role="user", content="Hello!"), ChatMessage(role="assistant", content="Hello!"), ChatMessage(role="user", content="Hello!")])
all_messages = self._prefix_messages + self._memory.get() chat_response = self._llm.chat(all_messages)
from llama_index.core.memory import ChatMemoryBuffer from llama_index.core.llms import ChatMessage llm = ... memory = ChatMemoryBuffer.from_defaults(llm=llm) memory.put(ChatMessage(role="user", content="Hello!")) all_messages = memory.get() resp = llm.chat(all_messages) memory.put(resp.message) memory.put(ChatMessage(role="user", content="Hello!")) all_messages = memory.get() resp = llm.chat(all_messages) memory.put(resp.message) ...
BadRequestError: Error code: 400 - {'object': 'error', 'message': 'After the optional system message, conversation roles must alternate user/assistant/user/assistant/...', 'type': 'BadRequestError', 'param': None, 'code': 400}
[ChatMessage(role=<MessageRole.USER: 'user'>, content='Hello!', additional_kwargs={}), ChatMessage(role=<MessageRole.ASSISTANT: 'assistant'>, content=" Hello! How can I help you today? Is there something specific you'd like to know or discuss? I'm here to answer questions and provide information on a wide range of topics. Let me know if you have any questions!", additional_kwargs={'tool_calls': []}), ChatMessage(role=<MessageRole.USER: 'user'>, content='Hello!', additional_kwargs={})]