[BUG] Invalid header value problem when using Ask-PDF
DylanWaken opened this issue · 3 comments
DylanWaken commented
Log as follows
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 127-858-063
key <key>
queryText What is the difference in the approach between this paper and original DDPM
fullText 34188 S CORE -B ASED G EN
INFO:werkzeug:127.0.0.1 - - [08/Apr/2023 11:53:56] "POST /getRelatedText HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/dylan/.local/lib/python3.10/site-packages/tenacity/__init__.py", line 382, in __call__
result = fn(*args, **kwargs)
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/embeddings/openai.py", line 147, in get_embeddings
data = openai.Embedding.create(input=list_of_text, engine=engine).data
File "/home/dylan/.local/lib/python3.10/site-packages/openai/api_resources/embedding.py", line 33, in create
response = super().create(*args, **kwargs)
File "/home/dylan/.local/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
File "/home/dylan/.local/lib/python3.10/site-packages/openai/api_requestor.py", line 216, in request
result = self.request_raw(
File "/home/dylan/.local/lib/python3.10/site-packages/openai/api_requestor.py", line 516, in request_raw
result = _thread_context.session.request(
File "/home/dylan/.local/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
File "/home/dylan/.local/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
File "/home/dylan/.local/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
resp = conn.urlopen(
File "/home/dylan/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/home/dylan/.local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/home/dylan/.local/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.10/http/client.py", line 1282, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.10/http/client.py", line 1323, in _send_request
self.putheader(hdr, value)
File "/home/dylan/.local/lib/python3.10/site-packages/urllib3/connection.py", line 224, in putheader
_HTTPConnection.putheader(self, header, *values)
File "/usr/lib/python3.10/http/client.py", line 1260, in putheader
raise ValueError('Invalid header value %r' % (values[i],))
ValueError: Invalid header value b'Bearer sk-YLFY<...OPENAI_KEY...>SS\n'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/dylan/.local/lib/python3.10/site-packages/flask/app.py", line 2551, in __call__
return self.wsgi_app(environ, start_response)
File "/home/dylan/.local/lib/python3.10/site-packages/flask/app.py", line 2531, in wsgi_app
response = self.handle_exception(e)
File "/home/dylan/.local/lib/python3.10/site-packages/flask/app.py", line 2528, in wsgi_app
response = self.full_dispatch_request()
File "/home/dylan/.local/lib/python3.10/site-packages/flask/app.py", line 1825, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/dylan/.local/lib/python3.10/site-packages/flask/app.py", line 1823, in full_dispatch_request
rv = self.dispatch_request()
File "/home/dylan/.local/lib/python3.10/site-packages/flask/app.py", line 1799, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/home/dylan/GPT-Zotero/zotero-gpt-helper/main.py", line 47, in getRelatedText
index = GPTSimpleVectorIndex.from_documents(
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/base.py", line 100, in from_documents
return cls(
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/vector_store/vector_indices.py", line 69, in __init__
super().__init__(
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/vector_store/base.py", line 54, in __init__
super().__init__(
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/base.py", line 69, in __init__
index_struct = self.build_index_from_nodes(nodes)
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/token_counter/token_counter.py", line 78, in wrapped_llm_predict
f_return_val = f(_self, *args, **kwargs)
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/vector_store/base.py", line 217, in build_index_from_nodes
return self._build_index_from_nodes(nodes)
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/vector_store/base.py", line 206, in _build_index_from_nodes
self._add_nodes_to_index(index_struct, nodes)
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/vector_store/base.py", line 178, in _add_nodes_to_index
embedding_results = self._get_node_embedding_results(
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/indices/vector_store/base.py", line 96, in _get_node_embedding_results
) = self._service_context.embed_model.get_queued_text_embeddings()
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/embeddings/base.py", line 151, in get_queued_text_embeddings
embeddings = self._get_text_embeddings(cur_batch_texts)
File "/home/dylan/.local/lib/python3.10/site-packages/llama_index/embeddings/openai.py", line 261, in _get_text_embeddings
embeddings = get_embeddings(texts, engine=engine)
File "/home/dylan/.local/lib/python3.10/site-packages/tenacity/__init__.py", line 289, in wrapped_f
return self(f, *args, **kw)
File "/home/dylan/.local/lib/python3.10/site-packages/tenacity/__init__.py", line 379, in __call__
do = self.iter(retry_state=retry_state)
File "/home/dylan/.local/lib/python3.10/site-packages/tenacity/__init__.py", line 326, in iter
raise retry_exc from fut.exception()
please fix this, thanks a lot
MuiseDestiny commented
Your openai key has a \n, you can delete it and try again.
DylanWaken commented
Problem elevated by changing line13 to:
with open("OPENAI_API_KEY.txt", "r", encoding="utf-8") as f:
os.environ["OPENAI_API_KEY"] = f.read().replace("\n", "")
It looks like an issue with file.read on linux as it reads the \n somehow, though my file is clearly only 1 line.
But the modifications above fixed the issue
thanks
MuiseDestiny commented
Problem elevated by changing line13 to:
with open("OPENAI_API_KEY.txt", "r", encoding="utf-8") as f: os.environ["OPENAI_API_KEY"] = f.read().replace("\n", "")It looks like an issue with file.read on linux as it reads the \n somehow, though my file is clearly only 1 line. But the modifications above fixed the issue thanks
Ok thank you, I will change these codes.