Skip to main content

A framework for orchestrating applications powered by autonomous AI agents and LLMs.

Project description

Logo of Gwenflow

A framework for orchestrating applications powered by autonomous AI agents and LLMs.

License: MIT GitHub release

Why Gwenflow?

Gwenflow, a framework designed by Gwenlake, streamlines the creation of customized, production-ready applications built around Agents and Large Language Models (LLMs). It provides developers with the tools necessary to integrate LLMs and Agents, enabling efficient and scalable solutions tailored to specific business or user needs.

Installation

Install from PyPI:

pip install gwenflow

Install from the main branch to try the newest features:

# install from Github
pip install -U git+https://github.com/gwenlake/gwenflow.git@main

Usage

Load your OpenAI api key from an environment variable:

import os
from gwenflow import ChatOpenAI

llm = ChatOpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)

or load your api key from a local .env file:

import os
import dotenv
from gwenflow import ChatOpenAI

dotenv.load_dotenv(override=True)  # load you api key from .env

llm = ChatOpenAI()

Chat

import os
from gwenflow import ChatOpenAI

dotenv.load_dotenv(override=True)  # load you api key from .env

messages = [
    {
        "role": "user",
        "content": "Describe Argentina in one sentence."
    }
]

llm = ChatOpenAI(model="gpt-4o-mini")
print(llm.invoke(messages=messages))

Agent

import os
from gwenflow import Agent

dotenv.load_dotenv(override=True)  # load you OpenAI api key from .env

# automatically use gpt-4o-mini for the Agent
agent = Agent(
    role="Agent",
    description="You are a helpful agent.",
)

response = agent.run("how are you?")
print(response.content)

Agents, Tasks and Tools

import requests
import json
import dotenv

from gwenflow import ChatOpenAI, Agent, Task, Tool

dotenv.load_dotenv(override=True)  # load you api key from .env


# tool to get fx
def get_exchange_rate(currency_iso: str) -> str:
    """Get the current exchange rate for a given currency. Currency MUST be in iso format."""
    try:
        response = requests.get("http://www.floatrates.com/daily/usd.json").json()
        data = response[currency_iso.lower()]
        return json.dumps(data)
    except Exception as e:
        print(f"Currency not found: {currency_iso}")
    return "Currency not found"


tool_get_exchange_rate = Tool.from_function(get_exchange_rate)

# llm, agent and task
llm = ChatOpenAI(model="gpt-4o-mini")

agentfx = Agent(
    role="Fx Analyst",
    instructions="Get recent exchange rates data.",
    llm=llm,
    tools=[tool_get_exchange_rate],
)

# Loop on a list of tasks
queries = [
    "Find the capital city of France?",
    "What's the exchange rate of the Brazilian real?",
    "What's the exchange rate of the Euro?",
    "What's the exchange rate of the Chine Renminbi?",
    "What's the exchange rate of the Chinese Yuan?",
    "What's the exchange rate of the Tonga?"
]

for query in queries:
    task = Task(
        description=query,
        expected_output="Answer in one sentence and if there is a date, mention this date.",
        agent=agentfx
    )
    print("")
    print("Q:", query)
    print("A:", task.run())
Q: Find the capital city of France?
A: The capital city of France is Paris.

Q: What's the exchange rate of the Brazilian real?
A: The exchange rate of the Brazilian real (BRL) is approximately 5.76, as of November 12, 2024.

Q: What's the exchange rate of the Euro?
A: The exchange rate of the Euro (EUR) is 0.9409 as of November 12, 2024.

Q: What's the exchange rate of the Chine Renminbi?
A: The exchange rate of the Chinese Renminbi (CNY) is 7.23 as of November 12, 2024.

Q: What's the exchange rate of the Chinese Yuan?
A: The exchange rate of the Chinese Yuan (CNY) is 7.23 as of November 12, 2024.

Q: What's the exchange rate of the Tonga?
A: The current exchange rate for the Tongan paʻanga (TOP) is 2.3662, as of November 12, 2024.

Automated Flows, Agents with Langchain Tools

Run an agent with Langchain tools. Requires langchain and pip install langchain-experimental

pip install langchain
pip install langchain-experimental

[!CAUTION]
Python REPL can execute arbitrary code on the host machine (e.g., delete files, make network requests). Use with caution. For more information general security guidelines, please see https://python.langchain.com/docs/security/.

import dotenv
from gwenflow import ChatOpenAI, Tool, AutoFlow

import langchain.agents
from langchain_experimental.utilities import PythonREPL
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper

# Load API key from .env file
dotenv.load_dotenv(override=True)

python_repl = PythonREPL()
python_repl_tool = langchain.agents.Tool(
    name="python_repl",
    description="This tool can execute python code and shell commands (pip commands to modules installation) Use with caution",
    func=python_repl.run,
)

api_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=5000)
wikipedia = WikipediaQueryRun(api_wrapper=api_wrapper)

tool_python = Tool.from_langchain(python_repl_tool)
tool_wikipedia = Tool.from_langchain(wikipedia)

llm = ChatOpenAI(model="gpt-4o")

flow = AutoFlow(llm=llm, tools=[tool_python, tool_wikipedia])
flow.generate_tasks(
    objective="Tell me about the biography of Kamala Harris and produce a pptx name biography_auto.pptx")
flow.run()

Contributing to Gwenflow

We are very open to the community's contributions - be it a quick fix of a typo, or a completely new feature! You don't need to be a Gwenflow expert to provide meaningful improvements.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gwenflow-0.5.1.tar.gz (42.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gwenflow-0.5.1-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

Details for the file gwenflow-0.5.1.tar.gz.

File metadata

  • Download URL: gwenflow-0.5.1.tar.gz
  • Upload date:
  • Size: 42.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for gwenflow-0.5.1.tar.gz
Algorithm Hash digest
SHA256 6ad29494581b16490ea283b4642dfa45bf05a62d128dff6a132a98b2fb116f45
MD5 2a933d5875c704d0b7398c93786528d1
BLAKE2b-256 a45d5eb53e3bdfe7768f08e5354d1e9eee5e2d7c0d6af4a00c06c21f003d3a38

See more details on using hashes here.

Provenance

The following attestation bundles were made for gwenflow-0.5.1.tar.gz:

Publisher: python-publish.yml on gwenlake/gwenflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gwenflow-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: gwenflow-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 60.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for gwenflow-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5bb64706e6510116aaf16436fc594d618524b2a6de4c17e2d5f6348efa86583
MD5 8e441f4c2c66df03b9bc0ca65b9f009a
BLAKE2b-256 0a2aac607975affb0965de758bf069658cfd0eebda9d35500162f95fd3d1bd86

See more details on using hashes here.

Provenance

The following attestation bundles were made for gwenflow-0.5.1-py3-none-any.whl:

Publisher: python-publish.yml on gwenlake/gwenflow

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page