from skills.skill import Skill import openai import os import requests from urllib.parse import quote # Python built-in URL encoding function #This Airtable Skill is tuned to work with our Airtable set up, where we are seaeching a specific column in a specific table, in a specific base. ll three variables need to be set below (Lines 55-59) class AirtableSearch(Skill): name = 'airtable_search' description = "A skill that retrieves data from our Airtable notes using a search. Useful for remembering who we talked to about a certain topic." api_keys_required = ['code_reader','skill_saver','documentation_search','text_completion'] def __init__(self, api_keys, main_loop_function): super().__init__(api_keys, main_loop_function) def execute(self, params, dependent_task_outputs, objective): if not self.valid: return # Initialize a list to keep track of queries tried tried_queries = [] # Modify the query based on the dependent task output if dependent_task_outputs != "": dependent_task = f"Use the dependent task output below as reference to help craft the correct search query for the provided task above. Dependent task output:{dependent_task_outputs}." else: dependent_task = "." # Initialize output output = '' while not output: # If there are tried queries, add them to the prompt tried_queries_prompt = f" Do not include search queries we have tried, and instead try synonyms or misspellings. Search queries we have tried: {', '.join(tried_queries)}." if tried_queries else "" print(tried_queries_prompt) query = self.text_completion_tool(f"You are an AI assistant tasked with generating a one word search query based on the following task: {params}. Provide only the search query as a response. {tried_queries_prompt} Take into account output from the previous task:{dependent_task}.\nExample Task: Retrieve data from Airtable notes using the skill 'airtable_search' to find people we have talked to about TED AI.\nExample Query:TED AI\nExample Task:Conduct a search in our Airtable notes to identify investors who have expressed interest in climate.\nExample Query:climate\nTask:{params}\nQuery:") # Add the query to the list of tried queries tried_queries.append(query) print("\033[90m\033[3m"+"Search query: " +str(query)+"\033[0m") # Retrieve the Airtable API key airtable_api_key = self.api_keys['airtable'] # Set the headers for the API request headers = { "Authorization": f"Bearer {airtable_api_key}", "Content-Type": "application/json" } # Set base id base_id = '' table_name = '