Skip to main content
Glama
Harnishnava

pokemon-api-server

main.cpython-313.pyc9.39 kB
� OƵg�� �b�SSKJrJr SSKJr SSKJr SSKJr SSK r SSK r SSK J r J r SSKrSSKJr SSKJr SS KJrJr SS KJr SS KJr SSKrSSKrSSKr\R<"\R>S 9 \R@"\!5r"\"5 \"5r#\#RI\S /S/SQS/S/SS9 \#RKS5S5r&Sr'\ RP"S5r)\)(d\*"S5e\"\)SS9r+\"S5r0Sq1Sr2"SS\5r3"S S!\5r4\#RkS"5S#5r6\#RoS$5S%5r8\#RsS&5S'\34S(j5r:g!\,a r-\"R]S\/"\-535 eSr-C-ff=f!\,a r-\"R]S\/"\-535 eSr-C-ff=f))�)�FastAPI� HTTPException)�CORSMiddleware)� JSONResponse)� BaseModelN)�List�Optional)� load_dotenv)�ChatGroq)� HumanMessage� SystemMessage)�RecursiveCharacterTextSplitter)�SentenceTransformer)�levelzhttp://localhost:3000T)�GET�POST�PUT�DELETE�OPTIONS�*i)� allow_origins�allow_credentials� allow_methods� allow_headers�expose_headers�max_age�httpc��,# �[RSURSUR35 U"U5IShv�N nU$N![a@n[R S[ U535 [SS[ U50S9sSnA$SnAff=f7f)NzIncoming request: � zRequest failed: ���detail)� status_code�content)�logger�info�method�url� Exception�error�strr)�request� call_next�response�es �<C:\Users\harni\Desktop\New folder\pokemon ai\backend\main.py� log_requestsr0&s���� �K�K�$�W�^�^�$4�A�g�k�k�]�C�D� �"�7�+�+����,�� � �� � �'��A��x�0�1����s�1�v�&� � �� �sD�0B� A�A�A�B�A� B�5B �B�B� B�Bzhttps://pokeapi.co/api/v2/�OPENAI_API_KEYz/GROQ_API_KEY not found in environment variableszllama-3.3-70b-versatile)� groq_api_key� model_namezError initializing Groq LLM: z&sentence-transformers/all-MiniLM-L6-v2z(Error initializing SentenceTransformer: c��# �/n[SS5H�n[R"[SU35nUR 5 UR 5nSUSSUSSS R US Vs/sH oDS SPM sn5S S R US Vs/sH oUSSPM sn5SUSSUSSS R USVs/sHofSSSUS3PM sn5S3nURU5 M� U(d [S5e[RU5n [R "U V s/sHn [R "U 5PM sn 5n [#[%X 55q[R)S[+U5S35 gs snfs snfs snf![a0n[RSUS[U535 SnAGM�SnAff=fs sn f![a=n[RS[U5S[,R."535 eSnAff=f7f)N��zpokemon/z Pokemon: �namez ID: �idz Types: z, �types�typez Abilities: � abilities�abilityz Height: �heightz Weight: �weightz Stats: �stats�statz: � base_statz zError fetching Pokemon z(No Pokemon data was fetched successfullyz'Successfully initialized database with z Pokemonz&Error in initialize_pokemon_database: � )�range�requests�get�POKEAPI_BASE_URL�raise_for_status�json�join�appendr(r$r)r*� ValueError�model�encode�np�array�list�zip� vector_storer%�len� traceback� format_exc) � pokemon_data�ir-�data�t�ar@� pokemon_infor.� embeddings�embs r/�initialize_pokemon_databaser^LsM���$�� ��q�#��A� �#�<�<�+;�*<�H�Q�C�(H�I���)�)�+��}�}���$��v�,��(��$�Z�L�!�� � �d�7�m�"L�m��V�9�V�#4�m�"L�M�N�O� �I�I�T�+�EV�&W�EV���|�F�';�EV�&W�X�Y�Z��h��(�)��h��(�)�� � �^b�cj�^k�"l�^k�VZ�6�l�6�&:�%;�2�d�;�>O�=P�#Q�^k�"l�m�n�o� � ��#�#�L�1��&��G�H� H��\�\�,�/� ��X�X� �C� ��r�x�x��}� �C�D� ��C� �9�:� �� � �=�c�,�>O�=P�PX�Y�Z��-#M��&W��#m��� �� � �6�q�c��C��F�8�D�E��� ��D�� ��� � �=�c�!�f�X�R� �H\�H\�H^�G_�`�a� ���s��H>�G4�AF2�4F#�F2�F(�.&F2�F-$�,F2�?G4�G/�%=G4�"H>�#F2�2 G,�<$G'� G4�'G,�,G4�4 H;�>8H6�6H;�;H>c� �\rSrSr%\\S'Srg)�Query�t�message�N)�__name__� __module__� __qualname__�__firstlineno__r*�__annotations__�__static_attributes__rc�r/r`r`ts�� �Lrjr`c�:�\rSrSr%\\S'Sr\\\\S'Sr g)� ChatResponse�wr-N�sourcesrc) rdrerfrgr*rhrnr rrircrjr/rlrlws���M�#'�G�X�d�3�i� �'rjrl�startupc��4# �[5IShv�N gN7f�N)r^rcrjr/� startup_eventrr{s��� %� '�'�'�s ����/c��# �SS0$7f)NrbzPokemon RAG AI APIrcrcrjr/�rootrus��� �+� ,�,�s�z/chat�queryc��# �[(d [SSS9e[RUR/5Sn/n[Hmup4[ R "X5[ RRU5[ RRU5-- nURXS45 Mo URSSS9 SRS USS 55n[S US 3S 9[URS 9/n[U5nURS5V s/sH-n SU ;dM U RS5SR!5PM/ n n [#UR$U S9$s sn f![&aOn [(R+S[-U 5S[.R0"535 [S[-U 5S9eSn A ff=f7f)Nr z Pokemon database not initialized)r"r!rc� �US$)Nrrc)�xs r/�<lambda>�chat.<locals>.<lambda>�s���!�rjT)�key�reverserBc3�(# �UH upUv� M g7frqrc)�.0�_�texts r/� <genexpr>�chat.<locals>.<genexpr>�s���A�0@�W�Q�D�0@�s��z�You are a knowledgeable Pokemon AI assistant. Use the following Pokemon information to answer questions accurately: z} Always be friendly and enthusiastic about Pokemon. If you're not sure about something, just say so.)r#zPokemon:r5)r-rnzError in chat endpoint: )rRrrLrMrbrN�dot�linalg�normrJ�sortrIr r �llm�split�striprlr#r(r$r)r*rTrU) rv�query_embedding� similaritiesr�� embedding� similarity�context�messages� ai_response�linernr.s r/�chatr��s����)<��|��C�8Z�[� [� �,�,�� � ��7��:��� �+�O�D�����;�� � ����/�"�)�)�.�.��2K�K��J� � � �� 2� 3� ,� ���n�d��;��)�)�A� �R�a�0@�A�A�� �' � �I�p�#s� t� ���� /�  ���(�m� �BI���t�AT�k�AT��Xb�fj�Xj�4�4�:�:�j�)�!�,�2�2�4�AT��k�� �(�(�� � ��l�� �<�� � �/��A��x�r�)�:N�:N�:P�9Q�R�S���C��F�;�;��<�sB�G �DE-� E(�,&E(�E-�'G �(E-�- G�7A G�G�G );�fastapirr�fastapi.middleware.corsr�fastapi.responsesr�pydanticrrD�os�typingrr rH�dotenvr �langchain_groqr �langchain_core.messagesr r �langchain_text_splittersr�sentence_transformersr�numpyrNrT�logging� basicConfig�INFO� getLoggerrdr$�app�add_middleware� middlewarer0rF�getenv�api_keyrKr�r(r.r)r*rLrRr^r`rl�on_eventrrrEru�postr�rcrjr/�<module>r�s���*�2�*��� �!� ��#�?�C�5�������'�,�,�'� � � �8� $�� � � �i������*�+��=��%��5� ��������  ��  �0��  ��i�i�(�)�G� ��J�K�K� ��,� �C� � � H� I�E� � �&�P�I��(�9�(����i��(��(������-��-����'��*<�e�*<��*<��M� � �L�L�0��Q���9�:� �� ��� � �L�L�;�C��F�8�D�E� �� �s0� (E�2F�F�%F�F�F.�F)�)F.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Harnishnava/pokemon-ai'

If you have feedback or need assistance with the MCP directory API, please join our Discord server