CoolFace
Apppublic

lawliet/CS224-knowledge-discovery

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
1likes
generate.cpython-39.pyc22 linesDownload Raw Back to __pycache__
1a

2�2d7�@s"ddlZddlZed�dd�ZdS)�N)�_qc�s�tjdt_d}d}t|d�D]"\}}|d|�d|d�d�7}q |j||d	�}tjjd3d|d�gd
�}|dddd|ddfS)N�OPENAI_API_KEYa�Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer. Always provide link as references and evidence.4    If you are unable to provide an answer, return most relevant reference with link. Always provide references.5    6    ---7    8    Always follow the following format:9    10    Question: ${{A scientific question that the user is asking}}11    Helpful Answer: ${{A scientific comprehensive and helpful answer}}12    Relevant References: ${{list of relevant references related to the Question with links}}13    14    ---15    16    {context}17 18    Question: {question}19    Helpful Answer:��matcheszSource-z: �metadataz20 21)�context�questionz
gpt-3.5-turbo�system)�role�content)�model�messages�choicesr�messager�usage�total_tokens)�os�environ�openai�api_key�	enumerate�format�ChatCompletion�create)r�query_response�prompt_templater�idx�data�prompt�response�r �R/Users/sri/CS/Academia/CS224U/projects/search_background/cs224u_qa/src/generate.py�get_openai_answers��22�r")rr�strr"r r r r!�<module>s