api-talk-chatgpt
v1.0.2
Published
Module for querying databases using OpenAI and automatically selecting the best endpoint.
Maintainers
Readme
��#� �Q�u�e�r�y� �A�s�s�i�s�t�a�n�t� �-� �O�p�e�n�A�I� �A�P�I� �Q�u�e�r�y� �M�o�d�u�l�e�
�
�
�
�#�#� �O�v�e�r�v�i�e�w�
�
�A�p�i� �T�a�l�k� �C�h�a�t�G�P�T� �i�s� �a�n� �N�P�M� �m�o�d�u�l�e� �t�h�a�t� �e�n�a�b�l�e�s� �a�u�t�o�m�a�t�i�c� �s�e�l�e�c�t�i�o�n� �o�f� �t�h�e� �b�e�s�t� �A�P�I� �e�n�d�p�o�i�n�t� �b�a�s�e�d� �o�n� �u�s�e�r� �q�u�e�r�i�e�s�.� �I�t� �u�s�e�s� �O�p�e�n�A�I�'�s� �G�P�T� �m�o�d�e�l�s� �t�o� �a�n�a�l�y�z�e� �t�h�e� �q�u�e�r�y�,� �f�e�t�c�h� �t�h�e� �r�e�l�e�v�a�n�t� �d�a�t�a� �f�r�o�m� �a�n� �A�P�I�,� �a�n�d� �f�o�r�m�a�t� �t�h�e� �r�e�s�p�o�n�s�e� �i�n� �a� �s�t�r�u�c�t�u�r�e�d� �m�a�n�n�e�r�.�
�
�
�
�#�#� �F�e�a�t�u�r�e�s�
�
�-� �' �A�u�t�o�m�a�t�i�c�a�l�l�y� �s�e�l�e�c�t�s� �t�h�e� �m�o�s�t� �a�p�p�r�o�p�r�i�a�t�e� �e�n�d�p�o�i�n�t� �b�a�s�e�d� �o�n� �t�h�e� �q�u�e�r�y�.�
�
�-� �' �E�n�s�u�r�e�s� �J�S�O�N� �r�e�s�p�o�n�s�e�s� �f�o�l�l�o�w� �a� �s�t�r�u�c�t�u�r�e�d� �f�o�r�m�a�t� �(��d�a�t�a�:� �[�]��)�.�
�
�-� �' �S�u�p�p�o�r�t�s� �O�p�e�n�A�I� �f�i�n�e�-�t�u�n�i�n�g� �w�i�t�h� �r�e�a�l� �A�P�I� �e�x�a�m�p�l�e�s�.�
�
�-� �' �T�r�a�c�k�s� �u�s�e�r� �s�e�s�s�i�o�n�s� �u�s�i�n�g� ��u�s�e�r�I�d�� �f�o�r� �p�e�r�s�o�n�a�l�i�z�e�d� �r�e�s�p�o�n�s�e�s�.�
�
�-� �' �S�u�p�p�o�r�t�s� �m�u�l�t�i�p�l�e� �r�e�s�p�o�n�s�e� �l�a�n�g�u�a�g�e�s� �b�a�s�e�d� �o�n� �u�s�e�r� �p�r�e�f�e�r�e�n�c�e�.�
�
�-� �' �A�l�l�o�w�s� �c�o�n�f�i�g�u�r�a�t�i�o�n� �o�f� �t�h�e� �O�p�e�n�A�I� �m�o�d�e�l� �a�n�d� �m�a�x�i�m�u�m� �t�o�k�e�n�s�.�
�
�-� �' �P�e�r�m�i�t�s� �o�v�e�r�r�i�d�i�n�g� �t�h�e� �d�e�f�a�u�l�t� �m�o�d�e�l� �a�n�d� �m�a�x� �t�o�k�e�n�s� �p�e�r� �q�u�e�r�y� �u�s�i�n�g� �t�h�e� ��o�p�t�i�o�n�s�� �p�a�r�a�m�e�t�e�r�.�
�
�-� �' �S�u�p�p�o�r�t�s� �d�e�f�i�n�i�n�g� ���h�e�a�d�e�r�s��� �(�e�.�g�.�,� �A�u�t�h�o�r�i�z�a�t�i�o�n�)�,� ���q�u�e�r�y� �p�a�r�a�m�e�t�e�r�s���,� �a�n�d� ���b�o�d�y��� �f�o�r� �e�a�c�h� �e�n�d�p�o�i�n�t�.�
�
�-� �' �S�u�p�p�o�r�t�s� ���c�h�a�i�n�i�n�g� �e�n�d�p�o�i�n�t�s���:� �y�o�u� �c�a�n� �d�e�f�i�n�e� �a� �s�e�c�o�n�d�a�r�y� �e�n�d�p�o�i�n�t� �(�e�.�g�.�,� �t�o� �g�e�t� �p�r�o�d�u�c�t� �p�r�i�c�e�)� �t�h�a�t� �i�s� �c�a�l�l�e�d� �a�f�t�e�r� �t�h�e� �p�r�i�m�a�r�y� �e�n�d�p�o�i�n�t�.�
�
�-� �' �S�i�m�p�l�e� �i�n�s�t�a�l�l�a�t�i�o�n� �a�n�d� �u�s�a�g�e� �a�c�r�o�s�s� �m�u�l�t�i�p�l�e� �p�r�o�j�e�c�t�s�.�
�
�-�-�-�
�
�
�
�#�#� �I�n�s�t�a�l�l�a�t�i�o�n�
�
�T�o� �i�n�s�t�a�l�l� �t�h�e� �p�a�c�k�a�g�e�,� �r�u�n�:�
�
�
�
����s�h�
�
�n�p�m� �i�n�s�t�a�l�l� �a�p�i�-�t�a�l�k�-�c�h�a�t�g�p�t�
�
����
�
�
�
�-�-�-�
�
�
�
�#�#� �U�s�a�g�e�
�
�#�#�#� �I�m�p�o�r�t� �a�n�d� �I�n�i�t�i�a�l�i�z�e�
�
����j�a�v�a�s�c�r�i�p�t�
�
�c�o�n�s�t� �Q�u�e�r�y�A�s�s�i�s�t�a�n�t� �=� �r�e�q�u�i�r�e�(�'�a�p�i�-�t�a�l�k�-�c�h�a�t�g�p�t�'�)�;�
�
�
�
�c�o�n�s�t� �a�s�s�i�s�t�a�n�t� �=� �n�e�w� �Q�u�e�r�y�A�s�s�i�s�t�a�n�t�(�{�
�
� � �o�p�e�n�A�I�A�p�i�K�e�y�:� �"�Y�O�U�R�_�O�P�E�N�A�I�_�A�P�I�_�K�E�Y�"�,�
�
� � �m�o�d�e�l�:� �"�g�p�t�-�4�"�,� � � � �/�/� �D�e�f�a�u�l�t� �m�o�d�e�l� �t�o� �u�s�e�
�
� � �m�a�x�T�o�k�e�n�s�:� �2�0�0� � � � � �/�/� �M�a�x�i�m�u�m� �t�o�k�e�n� �l�i�m�i�t� �p�e�r� �r�e�s�p�o�n�s�e�
�
�}�)�;�
�
����
�
�
�
�-�-�-�
�
�
�
�#�#� �D�e�f�i�n�i�n�g� �A�P�I� �E�n�d�p�o�i�n�t�s�
�
�E�a�c�h� �e�n�d�p�o�i�n�t� �s�h�o�u�l�d� �i�n�c�l�u�d�e�:�
�
�-� ��n�a�m�e��:� �A� �u�n�i�q�u�e� �i�d�e�n�t�i�f�i�e�r� �f�o�r� �t�h�e� �e�n�d�p�o�i�n�t�.�
�
�-� ��u�r�l��:� �T�h�e� �A�P�I� �U�R�L� �t�o� �f�e�t�c�h� �d�a�t�a� �f�r�o�m�.�
�
�-� ��d�e�s�c�r�i�p�t�i�o�n��:� �A� �s�h�o�r�t� �d�e�s�c�r�i�p�t�i�o�n� �o�f� �t�h�e� �e�n�d�p�o�i�n�t�.�
�
�-� ��e�x�a�m�p�l�e�s��:� �C�o�m�m�o�n� �q�u�e�r�i�e�s� �t�h�a�t� �w�o�u�l�d� �u�s�e� �t�h�i�s� �e�n�d�p�o�i�n�t�.�
�
�-� ��r�e�s�p�o�n�s�e�E�x�a�m�p�l�e��:� �A� �s�a�m�p�l�e� �r�e�s�p�o�n�s�e� �i�n� �t�h�e� �e�x�p�e�c�t�e�d� �f�o�r�m�a�t� �(��d�a�t�a�:� �[�]��)�.�
�
�
�
�
�
�A�d�d�i�t�i�o�n�a�l�l�y�,� �y�o�u� �c�a�n� �o�p�t�i�o�n�a�l�l�y� �i�n�c�l�u�d�e�:�
�
�-� ��m�e�t�h�o�d��:� �H�T�T�P� �m�e�t�h�o�d� �(�d�e�f�a�u�l�t� �i�s� �G�E�T�)�.�
�
�-� ��h�e�a�d�e�r�s��:� �A�n� �o�b�j�e�c�t� �w�i�t�h� �t�h�e� �n�e�c�e�s�s�a�r�y� �h�e�a�d�e�r�s� �(�e�.�g�.�,� �A�u�t�h�o�r�i�z�a�t�i�o�n�)�.�
�
�-� ��q�u�e�r�y��:� �A�n� �o�b�j�e�c�t� �w�i�t�h� �q�u�e�r�y� �p�a�r�a�m�e�t�e�r�s� �t�o� �a�p�p�e�n�d� �t�o� �t�h�e� �U�R�L�.�
�
�-� ��b�o�d�y��:� �T�h�e� �r�e�q�u�e�s�t� �b�o�d�y� �(�s�e�n�t� �a�s� �J�S�O�N� �i�f� �t�h�e� �m�e�t�h�o�d� �i�s� �n�o�t� �G�E�T�)�.�
�
�
�
�
�
�C�h�a�i�n�i�n�g� �E�n�d�p�o�i�n�t�s�
�
�Y�o�u� �c�a�n� �d�e�f�i�n�e� �a� �s�e�c�o�n�d�a�r�y� �e�n�d�p�o�i�n�t� �i�n� �a� �p�r�o�p�e�r�t�y� �n�a�m�e�d� �c�h�a�i�n�.� �I�f� �t�h�e� �p�r�i�m�a�r�y� �e�n�d�p�o�i�n�t� �r�e�t�u�r�n�s� �d�a�t�a� �(�e�.�g�.�,� �p�r�o�d�u�c�t� �i�n�f�o�r�m�a�t�i�o�n�)� �a�n�d� �r�e�q�u�i�r�e�s� �a� �f�o�l�l�o�w�-�u�p� �r�e�q�u�e�s�t� �(�e�.�g�.�,� �f�o�r� �p�r�i�c�i�n�g�)�,� �d�e�f�i�n�e� �t�h�e� �s�e�c�o�n�d�a�r�y� �e�n�d�p�o�i�n�t� �w�i�t�h� �t�h�e� �s�a�m�e� �o�p�t�i�o�n�a�l� �p�a�r�a�m�e�t�e�r�s� �(�u�r�l�,� �m�e�t�h�o�d�,� �h�e�a�d�e�r�s�,� �q�u�e�r�y�,� �a�n�d� �b�o�d�y�)�.� �T�h�e� �m�o�d�u�l�e� �w�i�l�l� �p�e�r�f�o�r�m� �t�h�e� �p�r�i�m�a�r�y� �A�P�I� �c�a�l�l� �a�n�d� �t�h�e�n� �e�x�e�c�u�t�e� �t�h�e� �c�h�a�i�n� �e�n�d�p�o�i�n�t�,� �c�o�m�b�i�n�i�n�g� �b�o�t�h� �r�e�s�p�o�n�s�e�s�.�
�
�
�
�E�x�a�m�p�l�e�:�
�
����j�a�v�a�s�c�r�i�p�t�
�
�c�o�n�s�t� �e�n�d�p�o�i�n�t�s� �=� �[�
�
� � �{�
�
� � � � �n�a�m�e�:� �"�P�r�o�d�u�c�t�I�n�f�o�"�,�
�
� � � � �u�r�l�:� �"�h�t�t�p�:�/�/�l�o�c�a�l�h�o�s�t�:�3�0�0�0�/�p�r�o�d�u�c�t�s�"�,�
�
� � � � �d�e�s�c�r�i�p�t�i�o�n�:� �"�R�e�t�r�i�e�v�e�s� �p�r�o�d�u�c�t� �i�n�f�o�r�m�a�t�i�o�n�.�"�,�
�
� � � � �e�x�a�m�p�l�e�s�:� �[�
�
� � � � � � �"�G�e�t� �p�r�o�d�u�c�t� �d�e�t�a�i�l�s�.�"�,�
�
� � � � � � �"�S�h�o�w� �m�e� �p�r�o�d�u�c�t� �i�n�f�o�.�"�
�
� � � � �]�,�
�
� � � � �r�e�s�p�o�n�s�e�E�x�a�m�p�l�e�:� �{�
�
� � � � � � �d�a�t�a�:� �[�
�
� � � � � � � � �{� �i�d�:� �1�,� �n�a�m�e�:� �"�P�r�o�d�u�c�t� �X�Y�Z�"�,� �a�v�a�i�l�a�b�l�e�:� �t�r�u�e� �}�
�
� � � � � � �]�
�
� � � � �}�,�
�
� � � � �/�/� �D�e�f�i�n�e� �a� �c�h�a�i�n� �e�n�d�p�o�i�n�t� �t�o� �r�e�t�r�i�e�v�e� �p�r�o�d�u�c�t� �p�r�i�c�e� �d�e�t�a�i�l�s�
�
� � � � �c�h�a�i�n�:� �{�
�
� � � � � � �u�r�l�:� �"�h�t�t�p�:�/�/�l�o�c�a�l�h�o�s�t�:�3�0�0�0�/�p�r�i�c�e�s�"�,�
�
� � � � � � �m�e�t�h�o�d�:� �"�G�E�T�"�,�
�
� � � � � � �q�u�e�r�y�:� �{�
�
� � � � � � � � �c�u�r�r�e�n�c�y�:� �"�U�S�D�"�
�
� � � � � � �}�,�
�
� � � � � � �h�e�a�d�e�r�s�:� �{�
�
� � � � � � � � �"�A�u�t�h�o�r�i�z�a�t�i�o�n�"�:� �"�B�e�a�r�e�r� �Y�O�U�R�_�T�O�K�E�N�_�H�E�R�E�"�
�
� � � � � � �}�
�
� � � � �}�
�
� � �}�
�
�]�;�
�
����
�
�
�
�-�-�-�
�
�
�
�#�#� �Q�u�e�r�y�i�n�g� �t�h�e� �A�s�s�i�s�t�a�n�t�
�
�#�#�#� �S�i�m�p�l�e� �Q�u�e�r�y� �w�i�t�h� �L�a�n�g�u�a�g�e� �P�r�e�f�e�r�e�n�c�e�
�
����j�a�v�a�s�c�r�i�p�t�
�
�a�s�y�n�c� �f�u�n�c�t�i�o�n� �r�u�n�Q�u�e�r�y�(�)� �{�
�
� � �c�o�n�s�t� �r�e�s�p�o�n�s�e� �=� �a�w�a�i�t� �a�s�s�i�s�t�a�n�t�.�g�e�t�R�e�s�p�o�n�s�e�(�"�S�h�o�w� �m�e� �t�h�e� �p�e�n�d�i�n�g� �o�r�d�e�r�s�"�,� �e�n�d�p�o�i�n�t�s�,� �[�]�,� �"�e�n�"�)�;�
�
� � �c�o�n�s�o�l�e�.�l�o�g�(�"�=�9� �R�e�s�p�o�n�s�e�:�"�,� �r�e�s�p�o�n�s�e�)�;�
�
�}�
�
�
�
�r�u�n�Q�u�e�r�y�(�)�;�
�
����
�
�
�
�#�#� �O�v�e�r�r�i�d�i�n�g� �t�h�e� �D�e�f�a�u�l�t� �M�o�d�e�l� �a�n�d� �M�a�x� �T�o�k�e�n�s�
�
�#�#�#� �Y�o�u� �c�a�n� �o�v�e�r�r�i�d�e� �t�h�e� �d�e�f�a�u�l�t� �m�o�d�e�l� �a�n�d� �m�a�x� �t�o�k�e�n�s� �o�n� �a� �p�e�r�-�q�u�e�r�y� �b�a�s�i�s� �b�y� �p�a�s�s�i�n�g� �t�h�e� �o�p�t�i�o�n�s� �p�a�r�a�m�e�t�e�r�:�
�
����j�a�v�a�s�c�r�i�p�t�
�
�a�s�y�n�c� �f�u�n�c�t�i�o�n� �r�u�n�C�u�s�t�o�m�Q�u�e�r�y�(�)� �{�
�
� � �c�o�n�s�t� �r�e�s�p�o�n�s�e� �=� �a�w�a�i�t� �a�s�s�i�s�t�a�n�t�.�g�e�t�R�e�s�p�o�n�s�e�(�
�
� � � � �"�S�h�o�w� �m�e� �t�h�e� �p�e�n�d�i�n�g� �o�r�d�e�r�s�"�,� �
�
� � � � �e�n�d�p�o�i�n�t�s�,� �
�
� � � � �[�]�,� �
�
� � � � �"�e�n�"�,� �
�
� � � � �{� �m�o�d�e�l�:� �"�g�p�t�-�3�.�5�-�t�u�r�b�o�"�,� �m�a�x�T�o�k�e�n�s�:� �1�5�0� �}�
�
� � �)�;�
�
� � �c�o�n�s�o�l�e�.�l�o�g�(�"�=�9� �C�u�s�t�o�m� �R�e�s�p�o�n�s�e�:�"�,� �r�e�s�p�o�n�s�e�)�;�
�
�}�
�
�
�
�r�u�n�C�u�s�t�o�m�Q�u�e�r�y�(�)�;�
�
����
�
�
�
�
�
�
�
�#�#�#� �H�a�n�d�l�i�n�g� �U�s�e�r� �S�e�s�s�i�o�n�s� �w�i�t�h� ��u�s�e�r�I�d��
�
�T�o� �m�a�i�n�t�a�i�n� �a� �c�o�n�v�e�r�s�a�t�i�o�n� �c�o�n�t�e�x�t�,� �p�a�s�s� �a� ��u�s�e�r�I�d�� �i�n� �t�h�e� ��m�e�s�s�a�g�e�s�� �a�r�r�a�y� �a�n�d� �s�p�e�c�i�f�y� �t�h�e� �p�r�e�f�e�r�r�e�d� �l�a�n�g�u�a�g�e�:�
�
����j�a�v�a�s�c�r�i�p�t�
�
�a�s�y�n�c� �f�u�n�c�t�i�o�n� �r�u�n�U�s�e�r�Q�u�e�r�y�(�)� �{�
�
� � �c�o�n�s�t� �m�e�s�s�a�g�e�s� �=� �[�
�
� � � � �{� �r�o�l�e�:� �"�s�y�s�t�e�m�"�,� �c�o�n�t�e�n�t�:� �"�Y�o�u� �a�r�e� �a�n� �A�P�I� �a�s�s�i�s�t�a�n�t�.�"� �}�,�
�
� � � � �{� �r�o�l�e�:� �"�u�s�e�r�"�,� �c�o�n�t�e�n�t�:� �"�W�h�a�t� �o�r�d�e�r�s� �a�r�e� �p�e�n�d�i�n�g�?�"�,� �u�s�e�r�I�d�:� �"�1�2�3�4�5�"� �}�
�
� � �]�;�
�
�
�
� � �c�o�n�s�t� �r�e�s�p�o�n�s�e� �=� �a�w�a�i�t� �a�s�s�i�s�t�a�n�t�.�g�e�t�R�e�s�p�o�n�s�e�(�"�W�h�a�t� �o�r�d�e�r�s� �a�r�e� �p�e�n�d�i�n�g�?�"�,� �e�n�d�p�o�i�n�t�s�,� �m�e�s�s�a�g�e�s�,� �"�e�s�"�)�;�
�
� � �c�o�n�s�o�l�e�.�l�o�g�(�"�=�9� �U�s�e�r� �R�e�s�p�o�n�s�e�:�"�,� �r�e�s�p�o�n�s�e�)�;�
�
�}�
�
�
�
�r�u�n�U�s�e�r�Q�u�e�r�y�(�)�;�
�
����
�
�
�
�-�-�-�
�
�
�
�#�#� �E�x�p�e�c�t�e�d� �O�u�t�p�u�t�
�
�I�f� �t�h�e� �q�u�e�r�y� �i�s�:� ���"�W�h�a�t� �o�r�d�e�r�s� �a�r�e� �p�e�n�d�i�n�g�?�"���,� �a�n�d� �t�h�e� �s�y�s�t�e�m� �s�e�l�e�c�t�s� �t�h�e� ��O�r�d�e�r�s�� �e�n�d�p�o�i�n�t�,� �t�h�e� �r�e�s�p�o�n�s�e� �w�i�l�l� �b�e�:�
�
����
�
�T�h�e� �f�o�l�l�o�w�i�n�g� �o�r�d�e�r�s� �a�r�e� �c�u�r�r�e�n�t�l�y� �p�e�n�d�i�n�g�:�
�
�-� �O�r�d�e�r� �I�D�:� �1�0�2�
�
� � �C�u�s�t�o�m�e�r�:� �J�a�n�e� �S�m�i�t�h�
�
� � �T�o�t�a�l�:� �$�2�5�0�.�0�0�
�
� � �S�t�a�t�u�s�:� �P�e�n�d�i�n�g�
�
����
�
�I�f� �t�h�e� �u�s�e�r� �s�e�l�e�c�t�s� �S�p�a�n�i�s�h� �(��"�e�s�"��)�,� �t�h�e� �r�e�s�p�o�n�s�e� �w�i�l�l� �b�e�:�
�
����
�
�L�o�s� �s�i�g�u�i�e�n�t�e�s� �p�e�d�i�d�o�s� �e�s�t���n� �p�e�n�d�i�e�n�t�e�s�:�
�
�-� �I�D� �d�e�l� �P�e�d�i�d�o�:� �1�0�2�
�
� � �C�l�i�e�n�t�e�:� �J�a�n�e� �S�m�i�t�h�
�
� � �T�o�t�a�l�:� �$�2�5�0�.�0�0�
�
� � �E�s�t�a�d�o�:� �P�e�n�d�i�e�n�t�e�
�
����
�
�
�
�-�-�-�
�
�
�
�#�#� �N�e�x�t� �S�t�e�p�s�
�
�-� �I�m�p�l�e�m�e�n�t� ���c�a�c�h�i�n�g��� �t�o� �o�p�t�i�m�i�z�e� �A�P�I� �c�a�l�l�s�.�
�
�-� �A�d�d� ���p�a�g�i�n�a�t�i�o�n� �s�u�p�p�o�r�t��� �f�o�r� �l�a�r�g�e� �d�a�t�a� �s�e�t�s�.�
�
�-� �E�x�t�e�n�d� ���u�s�e�r� �s�e�s�s�i�o�n� �t�r�a�c�k�i�n�g��� �f�o�r� �d�y�n�a�m�i�c� �c�o�n�v�e�r�s�a�t�i�o�n�s�.�
�
�
�
�F�o�r� �a�n�y� �i�s�s�u�e�s� �o�r� �f�e�a�t�u�r�e� �r�e�q�u�e�s�t�s�,� �f�e�e�l� �f�r�e�e� �t�o� �o�p�e�n� �a� �t�i�c�k�e�t� �o�n� �G�i�t�H�u�b�!� �=�
�
�
�
�
