We use cookies on our website.

Make LLM-powered webapps with ease

Lightweight

Has very few dependencies and a tiny package size

Asynchronous

Built from ground up to be async

LLM, DB Agnostic

Connect any LLM, Relational DB, Vector DB, Graph DB you want

Pub-Sub Event System

Build highly customizable workflows

Install the library

Bash
pip install embedia

Connect your LLM

Python
import openai
from embedia import ChatLLM
 
 
class OpenAIChatLLM(ChatLLM):
    def __init__(self):
        super().__init__()
        openai.api_key = "OPENAI_API_KEY"
 
    async def _reply(self, prompt):
        completion = await openai.ChatCompletion.acreate(
            model="gpt-3.5-turbo",
            temperature=0.1,
            messages=[
                {"role": msg.role, "content": msg.content} for msg in self.chat_history
            ],
        )
        return completion.choices[0].message.content

Use your AI Agent

Python
import asyncio
from embedia.agents import ToolUserAgent
from embedia.tools import PythonInterpreterTool, TerminalTool
 
# Create an AI agent and give it Tools
ai_agent = ToolUserAgent(
    chatllm=OpenAIChatLLM(), tools=[PythonInterpreterTool(), TerminalTool()]
)
 
# Ask the AI agent to solve a problem for you
question = "Find the number of lines of code in main.py"
asyncio.run(ai_agent(question))

Watch your AI Agent solve your problem with your confirmation

Bash
[time: 2023-10-03T19:34:46.058187+05:30] [id: 140226148785120] [event: Tool Start]
Tool: ToolUserAgent
Args: ('Find the number of lines of code in main.py',)
Kwargs: {}
 
[time: 2023-10-03T19:34:46.058287+05:30] [id: 140226148785120] [event: Agent Start]
Main Question:
Find the number of lines of code in main.py
 
[time: 2023-10-03T19:34:46.058323+05:30] [id: 140226137139040] [event: ChatLLM Init]
system (None tokens):
You're an expert in choosing the best tool for answering the user's question. The list of tools and their descriptions will be provided to you. Reply with the name of the chosen tool and nothing else
 
[time: 2023-10-03T19:34:46.060304+05:30] [id: 140226137139040] [event: ChatLLM Start]
user (None tokens):
Question: Find the number of lines of code in main.py
 
 Tools:
Python Interpreter: Runs the provided python code in the current interpreter
Terminal: Run the provided commands in the shell
 
[time: 2023-10-03T19:34:46.839806+05:30] [id: 140226137139040] [event: ChatLLM End]
assistant (None tokens):
Python Interpreter
 
[time: 2023-10-03T19:34:46.841584+05:30] [id: 140226137138896] [event: ChatLLM Init]
system (None tokens):
You're an expert in choosing the function arguments based on the user's question. The question, the function description, the list of parameters and their descriptions will be provided to you. Reply with all arguments in the following json format:
{
    <parameter name>: <argument value>,
    <parameter name>: <argument value>,
    <parameter name>: <argument value>,
}
Do not reply with anything else
 
[time: 2023-10-03T19:34:46.842617+05:30] [id: 140226137138896] [event: ChatLLM Start]
user (None tokens):
Question: Find the number of lines of code in main.py
Function: Runs the provided python code in the current interpreter
Parameters:
code: Python code to be run (type: str)
vars: A python dictionary containing variables to be passed to the code
timeout: Timeout in seconds (type: int). Defaults to 60.
 
 
[time: 2023-10-03T19:34:48.978232+05:30] [id: 140226137138896] [event: ChatLLM End]
assistant (None tokens):
{
    "code": "import os\n\nwith open('main.py', 'r') as file:\n    lines = file.readlines()\n\nnum_lines = len(lines)\nprint(num_lines)",
    "vars": {},
    "timeout": 60
}
 
Tool: ToolUserAgent
Details: {'tool': 'Python Interpreter', 'args': {'code': "import os\n\nwith open('main.py', 'r') as file:\n    lines = file.readlines()\n\nnum_lines = len(lines)\nprint(num_lines)", 'vars': {}, 'timeout': 60}} Confirm (y/n): y
 
[time: 2023-10-03T19:34:51.347248+05:30] [id: 140226121212256] [event: Tool Start]
Tool: PythonInterpreterTool
Args: ()
Kwargs: {'code': "import os\n\nwith open('main.py', 'r') as file:\n    lines = file.readlines()\n\nnum_lines = len(lines)\nprint(num_lines)", 'vars': {}, 'timeout': 60}
 
[time: 2023-10-03T19:34:51.953445+05:30] [id: 140226121212256] [event: Tool End]
Tool: PythonInterpreterTool
ExitCode: 0
Output:
32
 
 
[time: 2023-10-03T19:34:51.954520+05:30] [id: 140226148785120] [event: Agent Step]
Question: Find the number of lines of code in main.py
ToolChoice: Python Interpreter
ToolArgs: {'code': "import os\n\nwith open('main.py', 'r') as file:\n    lines = file.readlines()\n\nnum_lines = len(lines)\nprint(num_lines)", 'vars': {}, 'timeout': 60}
ToolExitCode: 0
ToolOutput: 32
 
 
[time: 2023-10-03T19:34:51.955140+05:30] [id: 140226137139088] [event: ChatLLM Init]
system (None tokens):
You're an expert in deciding what next question should be asked (if any) to reach the final answer. Your question will be acted upon and its result will be provided to you. This will repeat until we reach the final answer. The main question, actions taken till now and their results will be provided to you.
If we've reached the final answer, reply with the answer in the following format:
Final Answer: <final answer>
If not, reply with the next question in the following format:
Question: <next question>
Do not reply with anything else
 
[time: 2023-10-03T19:34:51.956013+05:30] [id: 140226137139088] [event: ChatLLM Start]
user (None tokens):
Main question: Find the number of lines of code in main.py
 
Question: Find the number of lines of code in main.py
 Output: 32
 
 
[time: 2023-10-03T19:34:52.558588+05:30] [id: 140226137139088] [event: ChatLLM End]
assistant (None tokens):
Final Answer: 32
 
[time: 2023-10-03T19:34:52.560265+05:30] [id: 140226148785120] [event: Agent End]
Final Answer:
 32
 
[time: 2023-10-03T19:34:52.561232+05:30] [id: 140226148785120] [event: Tool End]
Tool: ToolUserAgent
ExitCode: 0
Output:
 32

Try it out yourself

Please replace "OPENAI_API_KEY" with your OpenAI API key and run main.py