weaviate-python-client
weaviate-python-client copied to clipboard
Creates the function to set external API key
Implemented the set_apikey
function within the Client
class to set the different external API keys.
def set_apikey(self, openai_key: Optional[str] = None, cohere_key: Optional[str] = None, huggingface_key: Optional[str] = None, palm_key: Optional[str] = None):
...
This PR can close the issue #382
cc @tsmith023 @databyjp
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.
beep boop - the Weaviate bot 👋🤖
PS:
Are you already a member of the Weaviate Slack channel?
Note also the mypy
errors in the CI pipeline. If you've not used mypy
before then they're telling you that your function needs to have a return marked, i.e. -> None:
and it cannot determine the type of _headers
, which I think is solvable by adding self._headers: Dict[str, str] = {}
here
Codecov Report
Patch coverage: 11.11%
and project coverage change: -0.58%
:warning:
Comparison is base (
7528726
) 94.75% compared to head (848c5d6
) 94.18%. Report is 12 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #527 +/- ##
==========================================
- Coverage 94.75% 94.18% -0.58%
==========================================
Files 70 70
Lines 8492 8501 +9
==========================================
- Hits 8047 8007 -40
- Misses 445 494 +49
Files Changed | Coverage Δ | |
---|---|---|
weaviate/client.py | 89.28% <11.11%> (-9.39%) |
:arrow_down: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
@tsmith023 Thanks for the review. Soon making the desired changes.
@tsmith023 Hi Tommy I have made the following changes-
- Add
self._headers: Dict[str, str] = {}
line in connect/connection.py file - Add
-> None
in the function signature
Thanks Ankur
I am unable to add the tests
in the required file. I am afraid that it will take some time because I have my University exams.
@tsmith023 I have added unit tests.
I have my University exams
You should concentrate on these first! The PR can stay open until you have time to resume it, there's no pressure 😁
I have my University exams
You should concentrate on these first! The PR can stay open until you have time to resume it, there's no pressure 😁
Thanks for the patience, I am now available. If there are any changes required then please let me know.
@tsmith023 Any feedback regarding the PR.
Hi @ankur0904, sorry for not replying promptly! Because the CI pipeline is not fully green, it needs to be fixed before I will review it again. Could you look into the linting problems and unit test failures? Cheers 😁
@tsmith023 Ofcourse I will look into the failing CI pipeline.
Hey @tsmith023 any other changes required?
Hey @tsmith023 any other changes required?
Hi @ankur0904 - I can see that quite a few tests are failing here. Please take a look at the individual pipelines to see what is failing and try to address them.
As you can imagine, libraries like this one are our core products. And these automated tests are important parts of our quality assurance processes that help us ensure that any potential bugs or regressions do not get introduced into our products.
If you click on the Details
tab in the PR CI checklist, you can see the logs and stack trace, which should help you to see what is failing.
I see that the pipeline indicates the linting process to be failing, and some unit tests.
You can run these tests locally before committing / testing the changes through the CI/CD pipeline. You might have read this already, but the contributor guide includes a section on linting, and tests. So, please review these sections, and run those tests locally, which should mean that they pass on GH.
I hope that helps!
@databyjp Thanks for the guidance.
I checked each CI pipeline test, I found this test failure and confused how to fix it?
After running
$ pytest test --full-trace
self = <weaviate.client.Client object at 0x7f00886e77f0>, openai_key = 'your_key'
cohere_key = None, huggingface_key = None, palm_key = None
def set_apikey(self, openai_key: Optional[str] = None, cohere_key: Optional[str] = None, huggingface_key: Optional[str] = None, palm_key: Optional[str] = None) -> None:
"""
Set the external API key.
Parameters
----------
openai_key: str, optional
It is OpenAI API key.
cohere_key: str, optional
It is Cohere API key.
huggingface_key: str, optional
It is Hugging Face API key.
palm_key: str, optional
It is Palm API key.
Returns
-------
None
"""
if openai_key:
> self._connection._headers["x-openai-api-key"] = openai_key
E TypeError: 'Mock' object does not support item assignment
cohere_key = None
huggingface_key = None
openai_key = 'your_key'
palm_key = None
self = <weaviate.client.Client object at 0x7f00886e77f0>
weaviate/client.py:320: TypeError
Related File:
client.py
P.S. Meanwhile, I have fixed the linting issue
.
Thanks Ankur
I checked each CI pipeline test, I found this test failure and confused how to fix it?
Hi there, I'm not a Weaviate contributor - just passing by. It appears the Connection
class is patched out in line 13 of test_client.py. This patched version is just an empty Mock
object, so it isn't aware that it has a dictionary-like _headers
attribute. Try initializing the _headers
attribute with client._connection._headers = {}
prior to calling client.set_apikey()
in the test.
Also I believe the assertions in the new test will fail because the Client
class doesn't have the attribute additional_headers
- it only passes the init parameter to Connection
. Likewise, the Connection
class doesn't store additional_headers
, but parses into self._headers
. So instead of asserting client.additional_headers == ...
, I believe it should be client._connection._headers == ...
superseeded by https://github.com/weaviate/weaviate-python-client/pull/981