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 the main branch to try the newest features:

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.4.5.tar.gz (39.3 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.4.5-py3-none-any.whl (56.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gwenflow-0.4.5.tar.gz
Algorithm Hash digest
SHA256 08995251fabb033aed8cfce8ae3b51c6c6a8402e48828006a5ed2bc6171ed4b8
MD5 07c53cd74d2a66b716ca12e62b37b404
BLAKE2b-256 c69df9aa926733d8e8cf93cb42f0a136a081871422a44996dadfb466d7a6ba6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gwenflow-0.4.5.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.4.5-py3-none-any.whl.

File metadata

  • Download URL: gwenflow-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 56.7 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.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1dd86803f9b81b9eadbeda6dec2b3899819958360b78907c212c11310701e7e4
MD5 0720f9a4e86adf7917a4bfcdfa0053d3
BLAKE2b-256 fa10d0f7a265a52b04ab701c0e50f9aff7c8327e9f2f8087083994dc7e203fa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for gwenflow-0.4.5-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