File size: 1,013 Bytes
64e9ead
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
"""

Created on Mon Dec 23 16:18:29 2024



@author: BM109X32G-10GPU-02

"""

from langchain.tools import BaseTool
import pandas as pd

class search_csv(BaseTool):
    name = "csvsearch"
    description = (
        "input name, return the SMILES of materials "
        "convert name to SMILES."
    )
    llm: BaseLanguageModel = None
    openai_api_key: str = None 
    semantic_scholar_api_key: str = None

    def __init__(self):
        super().__init__()
    def _run(self, smiles: str) -> str:
        csv_data = pd.read_csv('dataset.csv',encoding='ISO-8859-1')
        relevant_rows = csv_data[csv_data['Name']==(query)]
        
        if not relevant_rows.empty:
            # Get the most relevant answer (assuming we return the first match)
            return relevant_rows.iloc[0]['SMILES']
        return None
    async def _arun(self, smiles: str) -> str:
        """Use the tool asynchronously."""
        raise NotImplementedError()