Hello ! I'm working on implementing ControlFlow u...
# marvin-ai
a
Hello ! I'm working on implementing ControlFlow using Docker Compose and have encountered an issue. I've set up a basic configuration, but I'm running into a connection timeout error when trying to start the Prefect API server. Error message: RuntimeError: Timed out while attempting to connect to ephemeral Prefect API server This error occurs in the following file: /usr/local/lib/python3.12/site-packages/prefect/client/orchestration.py, line 218, in get_client My current docker-compose.yml:
Copy code
services:
  cf:
    build: .
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - CONTROLFLOW_DEFAULT_LLM=${CONTROLFLOW_DEFAULT_LLM}
    develop:
     watch:
       - action: sync
         path: ./test.py
         target: /app/test.py
       - action: rebuild
         path: ./test.py
    stdin_open: true
    tty: true
My requirements.txt only includes controlflow and langchain_anthropic. The Python code I'm trying to run:
Copy code
import controlflow as cf
task = cf.Task(
    "Write a short poem about nature",
    result_type=str,
    instructions="Feel free to choose any poetic form that fits the theme."
)
task.run()
Could you please advise on what might be causing this timeout and how to resolve it? I think I'm totally missing some points... (I'm not familiar at all with Prefect and wanted to test out Controlflow, it seems really incredible !) Thank you for your help!
n
hi @Ahronn - in a setup like this, I'd recommend running a standalone container for your prefect server (or setting PREFECT_API_URL / PREFECT_API_KEY in order to point at cloud) if you want to run a prefect server backed by postgres, you can add this (as is, should be good to go) to the top of your docker compose file
Copy code
services:
  postgres:
    image: postgres:16
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: postgres

  prefect-server:
    image: prefecthq/prefect:3.0.0rc19-python3.12
    command: prefect --no-prompt server start --host 0.0.0.0
    ports:
      - 4200:4200
    environment:
      PREFECT_API_DATABASE_CONNECTION_URL: <postgresql+asyncpg://postgres:postgres@postgres:5432/postgres>

    depends_on:
      - postgres
and then your existing service below that would depend on these
feel free to ask if you have any questions about prefect itself, but the above should get you going with controlflow in your docker compose setting if you're not interested in digging into it now
d
I just run my code until it works - I think this is a temporary bug in the current version with some sort of minor race condition. 🙂
(check main channel for my little fix so far)
a
Thank you for the reply @Nate and @Dave Aitel, it works now fine after retrying until it works (with and without the addition in the docker compose) I have another non related question, it seems that the configuration in the quickstart does not work for Anthropic (with
Copy code
CONTROLFLOW_DEFAULT_LLM="anthropic/claude-3-haiku-20240307"
am I missing something ?) Anyway it works well with :
Copy code
import controlflow as cf

from langchain_anthropic import ChatAnthropic

model = ChatAnthropic(model="claude-3-haiku-20240307")

agent = cf.Agent(model=model)

task = cf.Task(
            "Write a short poem about nature",
            result_type=str,
            instructions="Feel free to choose any poetic form that fits the theme.",
            agents=[agent]
        )
        
task.run()
d
You are not missing anything. That doesn't work ...
I I really think the documentation needs a big workout over for that sort of thing
However the display is not as pretty as with openai :( I haven't debugged it yet
I still recommend you implement my little patch because while it will sometimes work, it will not be consistent without it
a
Yes I saw your fix and I think it would greatly help me ! I just have a question to implement it, I guess there are different ways but if you have any advice I'm all hear. I thought of inserting the patch in the desired line after installing the lib in my Dockerfile ?
d
To be honest, I am not that familiar with docker and I'm not exactly sure how I would do that :)
a
Oh ok ! I will try things and see if it works, thanks for the little patch !
d
No problem!
a
Well i managed to make it work, but the first execution still fails. Anyway it's better than before, thank you again ! 🙂
d
It's not consistent for me either....
Sadly