Package: lemonai
🍋 Lemon AIGateway to empower LLM agents to interact with the worldLemon AI helps you build powerful AI assistants in minutes and automate workflows by allowing for accurate and reliable read and write operations intoolslike Airtable, Hubspot, Discord, Notion, Slack and Github.Most connectors available today are focused on read-only operations, limiting the potential of LLMs. Agents, on the other hand, have a tendency to hallucinate from time to time due to missing context or instructions.With Lemon AI, it is possible to give your agents access to well-defined APIs for reliable read and write operations. In addition, Lemon AI functions allow you to further reduce the risk of hallucinations by providing a way to statically define workflows that the model can rely on in case of uncertainty.⚡️ Getting Started1. PrerequisitesRequires Python 3.8.1 and above.2. InstallingTo use Lemon AI in your Python project runpip install lemonai. The following example uses an OpenAI model. Therefore, we also need topip install openai. Depending on which model you want to use this install is optional.3. (Optional) Launch the serverThe interaction of your agents and all Lemon AI tools is provided by theLemon AI Server. Per default the Lemon AI Python client is sending requests to a hosted server version. To run the Lemon AI server on-prem please refer to theServer Documentation.4. Use Lemon AI with LangChainThe easiest way to give Lemon AI a try is via the Jupyter Notebook you can find in theLangChain Docs.Lemon AI automatically solves given tasks by finding the right combination of relevant tools or uses Lemon AI Functions as an alternative. The following example demonstrates how to retrieve a user from Hackernews and write it to a table in Airtable:Include Lemon AI in your LangChain projectimportosfromlemonaiimportexecute_workflowfromlangchainimportOpenAILoad API keys and access tokensTo use tools that require authentication, you have to store the corresponding access credentials in your environment in the format "{tool name}_{authentication string}" where the authentication string is one of ["API_KEY", "SECRET_KEY", "SUBSCRIPTION_KEY", "ACCESS_KEY"] for API keys or ["ACCESS_TOKEN", "SECRET_TOKEN"] for authentication tokens. Examples are "OPENAI_API_KEY", "BING_SUBSCRIPTION_KEY", "AIRTABLE_ACCESS_TOKEN".""" Load all relevant API Keys and Access Tokens into your environment variables """os.environ["OPENAI_API_KEY"]="*INSERT OPENAI API KEY HERE*"os.environ["GITHUB_API_KEY"]="*INSERT GITHUB API KEY HERE*"os.environ["DISCORD_WEBHOOK_URL"]="*INSERT DISCORD CHANNEL WEBHOOK URL HERE*"Example of defining your prompt and executing the Langchain AgentThe following example makes use of several Lemon AI tools toRetrieve details about a personal repository on GitHubGet the top growing starred repositories of my accountSend a Discord message with results and review.lemonai_repo_owner="Abdus2609"github_username="Abdus2609"""" Define your instruction to be given to your LLM """prompt=f"""Get the description for a repository I am working with called lemonai (owner{lemonai_repo_owner}).Also, get my top growing starred repositories (username{github_username}). Analyze the descriptions of boththe LemonAI repository and my top-starred repositories. Then, send a Discord message that first displays anumerically bullet-pointed leaderboard of the top growing starred repositories and their growth, and secondlydiscuss how each tool could be useful specifically to lemonai's use case based on your analysis of thedescriptions of each repository.""""""Use the Lemon AI execute_workflow wrapperto run your LangChain agent in combination with Lemon AI"""model=OpenAI(temperature=0)execute_workflow(llm=model,prompt_string=prompt)(Optional) Define your Lemon AI FunctionsSimilar toOpenAI functions, Lemon AI provides the option to define workflows as reusable functions. These functions can be defined for use cases where it is especially important to move as close as possible to near-deterministic behavior. Specific workflows can be defined in a separate lemonai.json. You can find the corresponding tool ids (e.g.hackernews-get-user) in theTool Docs:[{"name":"Hackernews Airtable User Workflow","description":"retrieves user data from Hackernews and appends it to a table in Airtable","tools":["hackernews-get-user","airtable-append-data"]}]Your model will have access to these functions and will prefer them over self-selecting tools to solve a given task. All you have to do is to let the agent know that it should use a given function by including the function name in the prompt (e.g.prompt = f"""Execute the Hackernews Airtable user workflow...).5. Gain transparency on your Agent's decision makingTo gain transparency on how your Agent interacts with Lemon AI tools to solve a given task, all decisions made, tools used and operations performed are written to a locallemonai.logfile. Every time your LLM agent is interacting with the Lemon AI tool stack a corresponding log entry is created:2023-06-26T11:50:27.708785+0100 - b5f91c59-8487-45c2-800a-156eac0c7dae - hackernews-get-user
2023-06-26T11:50:39.624035+0100 - b5f91c59-8487-45c2-800a-156eac0c7dae - airtable-append-data
2023-06-26T11:58:32.925228+0100 - 5efe603c-9898-4143-b99a-55b50007ed9d - hackernews-get-user
2023-06-26T11:58:43.988788+0100 - 5efe603c-9898-4143-b99a-55b50007ed9d - airtable-append-dataBy using theLemon AI Analytics Toolyou can easily gain a better understanding of how frequently and in which order tools are used. As a result, you can identify weak spots in your agent’s decision-making capabilities and move to a more deterministic behavior by defining Lemon AI functions.🧩 Supported ToolsWe already allow agents to interact with over120 toolsacross the following services:HackerNewsAirtableSlackHubSpotGithubNotionDiscord🩻 Next UpGithubNotionDiscordGmailGoogle CalendarKafkaPipedriveMonday.comStripeMediumGoogle Cloud Realtime DatabaseSalesforce🦸 ContributingGreat to see you here! We are extremely open to contributions! You can find more information in ourCONTRIBUTING.md. If you have any more questions feel free to drop us a message onDiscord.❤️‍🔥 ContributorsThose are the team members and people who actively help out improving the codebase by making PRs and reviewing code. We are beyond grateful for your help!Felix BrockmeierMohammed HannanHai NghiemClemens Schroeer