Closed Philipzhong1980 closed 7 months ago
🤖
Hello @Philipzhong1980,
From the traceback you provided, it seems like the error is originating from the OpenAI's API request. Specifically, the error is raised when the API response is being interpreted. The error message AttributeError: 'str' object has no attribute 'get'
suggests that the API response is a string, but the code is expecting a dictionary.
This could be due to a few reasons:
The API request to OpenAI is not successful, and the response is an error message in string format. You can check the status of the API request by printing the response before it's interpreted.
The OpenAI API has changed its response format. You can check the OpenAI API documentation to confirm the expected response format.
There might be a bug in the LangChain's OpenAI embedding code that incorrectly handles the API response.
To further investigate this issue, you could try the following:
I hope this helps! If you have any more information or if the issue persists, please feel free to share.
Best, Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
Hi, @Philipzhong1980,
I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you encountered an error related to an AttributeError when using Langchain, OpenAI, and Milvus. Dosubot provided a detailed response with steps to investigate the issue further, including checking the API request status, updating packages, and making a simple API request outside of LangChain.
Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, kindly let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!
System Info
Milvus standlone:2.3.2 Langchain version:0.0.325 OpenAI: 0.28.1 pymilvus: 2.3.2 Pydantic:2.4.2
Who can help?
No response
Information
Related Components
Reproduction
this is my testing coding import os import openai import langchain from langchain.chains import RetrievalQAWithSourcesChain from langchain.chat_models import AzureChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter from langchain.vectorstores import Milvus from langchain.document_loaders import WebBaseLoader
langchain.debug = True
MILVUS_HOST = "10.224.122.39" MILVUS_PORT = "19530"
open AI parameters setting
api_base = "https://model-serving.us-east-2.int.infra.intelligence.webex.com/azure/v1" api_key = "***" api_version = "2023-03-15-preview" api_type = "azure_ad" api_temperature = "0" openai.api_type = api_type openai.api_version = api_version openai.api_base = api_base openai.api_key = api_key os.environ["OPENAI_API_KEY"] = api_key os.environ["OPENAI_API_BASE"] = api_base os.environ["TOKENIZERS_PARALLELISM"] = "false"
def insert_vector2DB(): text_splitter_chunk_size = 2000 text_splitter_chunk_overlap = 200
def query(question):
def __test_query(): query("What is IP DECT 6800?") query("What is Webex Calling?") query("What is Milvus?")
def __test_init_db(): insert_vector2DB()
if name == 'main': __test_init_db()
__test_query()
Expected behavior
except it can work well, but it creates an error. Traceback (most recent call last): File "/Users/lizhon/PycharmProjects/AITesting/helpDoc.py", line 169, in
test_init_db()
File "/Users/lizhon/PycharmProjects/AITesting/helpDoc.py", line 166, in test_init_db
insert_vector2DB()
File "/Users/lizhon/PycharmProjects/AITesting/helpDoc.py", line 70, in insert_vector2DB
Milvus.from_documents(
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/schema/vectorstore.py", line 438, in from_documents
return cls.from_texts(texts, embedding, metadatas=metadatas, kwargs)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/vectorstores/milvus.py", line 827, in from_texts
vector_db.add_texts(texts=texts, metadatas=metadatas)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/vectorstores/milvus.py", line 427, in add_texts
embeddings = self.embedding_func.embed_documents(texts)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/embeddings/openai.py", line 490, in embed_documents
return self._get_len_safe_embeddings(texts, engine=self.deployment)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/embeddings/openai.py", line 374, in _get_len_safe_embeddings
response = embed_with_retry(
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/embeddings/openai.py", line 107, in embed_with_retry
return _embed_with_retry(kwargs)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/tenacity/init.py", line 289, in wrapped_f
return self(f, *args, kw)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/tenacity/init.py", line 379, in call
do = self.iter(retry_state=retry_state)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/tenacity/init.py", line 314, in iter
return fut.result()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/concurrent/futures/_base.py", line 437, in result
return self.get_result()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/concurrent/futures/_base.py", line 389, in get_result
raise self._exception
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/tenacity/init.py", line 382, in call
result = fn(args, kwargs)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/langchain/embeddings/openai.py", line 104, in _embed_with_retry
response = embeddings.client.create(kwargs)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/openai/api_resources/embedding.py", line 33, in create
response = super().create(args, kwargs)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/openai/api_resources/abstract/engine_apiresource.py", line 155, in create
response, , api_key = requestor.request(
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/openai/api_requestor.py", line 299, in request
resp, got_stream = self._interpret_response(result, stream)
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/openai/api_requestor.py", line 710, in _interpret_response
self._interpret_response_line(
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/openai/api_requestor.py", line 775, in _interpret_response_line
raise self.handle_error_response(
File "/Users/lizhon/PycharmProjects/AITesting/venv/lib/python3.8/site-packages/openai/api_requestor.py", line 428, in handle_error_response
error_code=error_data.get("code"),
AttributeError: 'str' object has no attribute 'get'
Process finished with exit code 1