o
    h                     @   sF   d dl Z d dlZd dlmZ e  dd Zdedejdefdd	ZdS )
    N)load_dotenvc                  C   s    t d} | stdt| S )NCOHERE_API_KEYz'COHERE_API_KEY not found in environment)osgetenvRuntimeErrorcohereClient)api_key r
   ;/var/www/qbot.qaapt.com/qbot.qaapt.com/app/funder_parser.pyget_cohere_client   s   

r   textcoreturnc              
   C   s\   d|  d}z|j d|ddd}|jd j W S  ty- } z	tdt| d }~ww )	NaI  You are an expert in funding data extraction.

Extract the funding information from the following text and return *only* valid JSON. Do not add any explanation or preamble.

Required JSON keys:
- funder_name
- funding_amount (can be null)
- currency (can be null)
- program_name (can be null)
- grant_period (can be null)

Text:
zA

Respond with JSON only. No explanation, no markdown formatting.zcommand-r-plusg?i,  )modelprompttemperature
max_tokensr   zFunding parsing failed: )generategenerationsr   strip	Exceptionr   str)r   r   r   responseer
   r
   r   parse_funding_text   s    	r   )r   r   dotenvr   r   r   r   r   r
   r
   r
   r   <module>   s    