Closed gmdl007 closed 4 months ago
🤖
Hey there, @gmdl007! 👋 I'm Dosu, a friendly bot here to lend a hand with bugs, answer your questions, and guide you towards becoming a stellar contributor while we wait for a human maintainer. I'm all geared up to assist you, so let's dive into your issue and see how we can untangle it together. Hang tight, I'll have a more detailed look and get back to you shortly!
my llm code is simple:
from llama_index.llms.azure_openai import AzureOpenAI from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
api_key = xyz.json()["access_token"] azure_endpoint = "https://chat-ai.xyz.com/" api_version = "2023-08-01-preview"
llm = AzureOpenAI( model="gpt-35-turbo", deployment_name="gpt-4", api_key=api_key, azure_endpoint=azure_endpoint, api_version=api_version, )
if i use :
index = VectorStoreIndex.from_documents(documents)
it works just fine...
but not for KG:
index = KnowledgeGraphIndex.from_documents( documents, max_triplets_per_chunk=10, storage_context=storage_context, include_embeddings=True, show_progress=True )
Seems like somehow, it is calling llm.chat()
with an empty list of messages?
If you had the full traceback, it would be helpful
🤖
Based on the error message you provided, it seems like the server is unable to process the request due to some missing fields. The error code 422 typically indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions. This could be due to missing fields, incorrect data types, or data that does not conform to expected schemas.
Looking at the code snippet you provided, it seems like you're trying to create a KnowledgeGraphIndex
from a set of documents. However, based on the context provided, the KnowledgeGraphIndex.from_documents
function does not exist in the LlamaIndex codebase. This could potentially be the source of the error.
In the LlamaIndex repository, there have been similar issues reported by other users. For instance, issue #6266 and issue #7312 both discuss problems related to the AzureOpenAI integration. These issues might provide some insight into your problem.
To resolve this issue, you could try the following steps:
Review Data and Schema: Ensure that the data being processed and sent to Azure OpenAI matches the expected schema and data types. This includes reviewing the transformations applied in _create_index_document
and ensuring that all required fields are present and correctly formatted.
Check Index Configuration: Review the index configuration and management strategy to ensure that it aligns with the capabilities and requirements of Azure OpenAI. This includes the vector search and semantic search configurations.
Adjust Batch Processing: If the issue might be related to batch size or document content size, try adjusting the batch size to see if smaller batches are processed successfully.
Debug and Log: Increase logging around the data processing and submission steps to capture more detailed information about the data being sent when the error occurs. This can help identify specific data issues or patterns that lead to the error.
If you could provide more information about the KnowledgeGraphIndex.from_documents
function and how it's implemented in your code, it would be easier to pinpoint the exact cause of the issue.
here is my complete code and error log:
api_key = token_response.json()["xxxxxx"] azure_endpoint = "https://www.xxx.com" api_version = "2023-08-01-preview"
llm = AzureOpenAI( model="gpt-35-turbo-16k", deployment_name="gpt-35-turbo", api_key=api_key, azure_endpoint=azure_endpoint, api_version=api_version, )
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.core import Settings
Settings.llm = llm Settings.embed_model = HuggingFaceEmbedding(model_name='jinaai/jina-embeddings-v2-base-en', pooling='mean', trust_remote_code=True, max_length=512, device="cpu")
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
documents = SimpleDirectoryReader( "/txt_2/" ).load_data() index = VectorStoreIndex.from_documents(documents)
query = "What is most interesting about this essay?" query_engine = index.as_query_engine() answer = query_engine.query(query)
print(answer.get_formatted_sources()) print("query was:", query) print("answer was:", answer)
here comes the errors:
huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks... To disable this warning, you can either:
tokenizers
before the fork if possibleUnprocessableEntityError Traceback (most recent call last) Cell In[8], line 3 1 query = "What is most interesting about this essay?" 2 query_engine = index.as_query_engine() ----> 3 answer = query_engine.query(query) 5 print(answer.get_formatted_sources()) 6 print("query was:", query)
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/base/base_query_engine.py:40, in BaseQueryEngine.query(self, str_or_query_bundle) 38 if isinstance(str_or_query_bundle, str): 39 str_or_query_bundle = QueryBundle(str_or_query_bundle) ---> 40 return self._query(str_or_query_bundle)
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/query_engine/retriever_query_engine.py:187, in RetrieverQueryEngine._query(self, query_bundle) 183 with self.callback_manager.event( 184 CBEventType.QUERY, payload={EventPayload.QUERY_STR: query_bundle.query_str} 185 ) as query_event: 186 nodes = self.retrieve(query_bundle) --> 187 response = self._response_synthesizer.synthesize( 188 query=query_bundle, 189 nodes=nodes, 190 ) 192 query_event.on_end(payload={EventPayload.RESPONSE: response}) 194 return response
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/response_synthesizers/base.py:180, in BaseSynthesizer.synthesize(self, query, nodes, additional_source_nodes, response_kwargs) 175 query = QueryBundle(query_str=query) 177 with self._callback_manager.event( 178 CBEventType.SYNTHESIZE, payload={EventPayload.QUERY_STR: query.query_str} 179 ) as event: --> 180 response_str = self.get_response( 181 query_str=query.query_str, 182 text_chunks=[ 183 n.node.get_content(metadata_mode=MetadataMode.LLM) for n in nodes 184 ], 185 response_kwargs, 186 ) 188 additional_source_nodes = additional_source_nodes or [] 189 source_nodes = list(nodes) + list(additional_source_nodes)
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/response_synthesizers/compact_and_refine.py:38, in CompactAndRefine.get_response(self, query_str, text_chunks, prev_response, response_kwargs) 34 # use prompt helper to fix compact text_chunks under the prompt limitation 35 # TODO: This is a temporary fix - reason it's temporary is that 36 # the refine template does not account for size of previous answer. 37 new_texts = self._make_compact_text_chunks(query_str, text_chunks) ---> 38 return super().get_response( 39 query_str=query_str, 40 text_chunks=new_texts, 41 prev_response=prev_response, 42 response_kwargs, 43 )
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/response_synthesizers/refine.py:160, in Refine.get_response(self, query_str, text_chunks, prev_response, response_kwargs) 156 for text_chunk in text_chunks: 157 if prev_response is None: 158 # if this is the first chunk, and text chunk already 159 # is an answer, then return it --> 160 response = self._give_response_single( 161 query_str, text_chunk, response_kwargs 162 ) 163 else: 164 # refine response if possible 165 response = self._refine_response_single( 166 prev_response, query_str, text_chunk, **response_kwargs 167 )
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/response_synthesizers/refine.py:214, in Refine._give_response_single(self, query_str, text_chunk, response_kwargs) 210 if response is None and not self._streaming: 211 try: 212 structured_response = cast( 213 StructuredRefineResponse, --> 214 program( 215 context_str=cur_text_chunk, 216 response_kwargs, 217 ), 218 ) 219 query_satisfied = structured_response.query_satisfied 220 if query_satisfied:
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/response_synthesizers/refine.py:68, in DefaultRefineProgram.call(self, *args, kwds) 66 answer = answer.json() 67 else: ---> 68 answer = self._llm.predict( 69 self._prompt, 70 kwds, 71 ) 72 return StructuredRefineResponse(answer=answer, query_satisfied=True)
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/llms/llm.py:253, in LLM.predict(self, prompt, prompt_args) 251 if self.metadata.is_chat_model: 252 messages = self._get_messages(prompt, prompt_args) --> 253 chat_response = self.chat(messages) 254 output = chat_response.message.content or "" 255 else:
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/core/llms/callbacks.py:93, in llm_chat_callback.
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/llms/openai/base.py:237, in OpenAI.chat(self, messages, kwargs) 235 else: 236 chat_fn = completion_to_chat_decorator(self._complete) --> 237 return chat_fn(messages, kwargs)
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/llama_index/llms/openai/base.py:296, in OpenAI._chat(self, messages, kwargs) 294 client = self._get_client() 295 message_dicts = to_openai_message_dicts(messages) --> 296 response = client.chat.completions.create( 297 messages=message_dicts, 298 stream=False, 299 self._get_model_kwargs(**kwargs), 300 ) 301 openai_message = response.choices[0].message 302 message = from_openai_message(openai_message)
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/openai/_utils/_utils.py:275, in required_args.
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/openai/resources/chat/completions.py:663, in Completions.create(self, messages, model, frequency_penalty, function_call, functions, logit_bias, logprobs, max_tokens, n, presence_penalty, response_format, seed, stop, stream, temperature, tool_choice, tools, top_logprobs, top_p, user, extra_headers, extra_query, extra_body, timeout) 611 @required_args(["messages", "model"], ["messages", "model", "stream"]) 612 def create( 613 self, (...) 661 timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, 662 ) -> ChatCompletion | Stream[ChatCompletionChunk]: --> 663 return self._post( 664 "/chat/completions", 665 body=maybe_transform( 666 { 667 "messages": messages, 668 "model": model, 669 "frequency_penalty": frequency_penalty, 670 "function_call": function_call, 671 "functions": functions, 672 "logit_bias": logit_bias, 673 "logprobs": logprobs, 674 "max_tokens": max_tokens, 675 "n": n, 676 "presence_penalty": presence_penalty, 677 "response_format": response_format, 678 "seed": seed, 679 "stop": stop, 680 "stream": stream, 681 "temperature": temperature, 682 "tool_choice": tool_choice, 683 "tools": tools, 684 "top_logprobs": top_logprobs, 685 "top_p": top_p, 686 "user": user, 687 }, 688 completion_create_params.CompletionCreateParams, 689 ), 690 options=make_request_options( 691 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout 692 ), 693 cast_to=ChatCompletion, 694 stream=stream or False, 695 stream_cls=Stream[ChatCompletionChunk], 696 )
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/openai/_base_client.py:1200, in SyncAPIClient.post(self, path, cast_to, body, options, files, stream, stream_cls) 1186 def post( 1187 self, 1188 path: str, (...) 1195 stream_cls: type[_StreamT] | None = None, 1196 ) -> ResponseT | _StreamT: 1197 opts = FinalRequestOptions.construct( 1198 method="post", url=path, json_data=body, files=to_httpx_files(files), **options 1199 ) -> 1200 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/openai/_base_client.py:889, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls) 880 def request( 881 self, 882 cast_to: Type[ResponseT], (...) 887 stream_cls: type[_StreamT] | None = None, 888 ) -> ResponseT | _StreamT: --> 889 return self._request( 890 cast_to=cast_to, 891 options=options, 892 stream=stream, 893 stream_cls=stream_cls, 894 remaining_retries=remaining_retries, 895 )
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/openai/_base_client.py:980, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 977 err.response.read() 979 log.debug("Re-raising status error") --> 980 raise self._make_status_error_from_response(err.response) from None 982 return self._process_response( 983 cast_to=cast_to, 984 options=options, (...) 987 stream_cls=stream_cls, 988 )
UnprocessableEntityError: Error code: 422 - {'detail': [{'loc': ['body', 'user'], 'msg': 'field required', 'type': 'value_error.missing'}]}
Question Validation
Question
i am keep getting this using Azure OpenAI, it is a internal one of cause:
File ~/miniforge3/envs/new2/lib/python3.11/site-packages/openai/_base_client.py:980, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls) 977 err.response.read() 979 log.debug("Re-raising status error") --> 980 raise self._make_status_error_from_response(err.response) from None 982 return self._process_response( 983 cast_to=cast_to, 984 options=options, (...) 987 stream_cls=stream_cls, 988 )
UnprocessableEntityError: Error code: 422 - {'detail': [{'loc': ['body', 'user'], 'msg': 'field required', 'type': 'value_error.missing'}]}
What can this be?
Many Thanks