Working on docs.

This commit is contained in:
Brandon Hancock
2024-09-19 16:40:31 -04:00
parent cbff4bb967
commit d63750705c
3 changed files with 234 additions and 15 deletions

View File

@@ -169,9 +169,18 @@ class Flow(Generic[T], metaclass=FlowMeta):
if not self._start_methods:
raise ValueError("No start method defined")
for start_method in self._start_methods:
result = await self._execute_method(self._methods[start_method])
await self._execute_listeners(start_method, result)
# Create tasks for all start methods
tasks = [
self._execute_start_method(start_method)
for start_method in self._start_methods
]
# Run all start methods concurrently
await asyncio.gather(*tasks)
async def _execute_start_method(self, start_method: str):
result = await self._execute_method(self._methods[start_method])
await self._execute_listeners(start_method, result)
async def _execute_method(self, method: Callable, *args, **kwargs):
if asyncio.iscoroutinefunction(method):

View File

@@ -5,16 +5,16 @@ from openai import OpenAI
class ExampleFlow(Flow):
client = OpenAI()
model = "gpt-4o-mini"
@start()
def start_method(self):
def generate_city(self):
print("Starting flow")
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
response = self.client.chat.completions.create(
model=self.model,
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{
"role": "user",
"content": "Return the name of a random city in the world.",
@@ -23,14 +23,25 @@ class ExampleFlow(Flow):
)
random_city = response.choices[0].message.content
print("random_city", random_city)
print("---- Random City ----")
print(random_city)
return random_city
@listen(start_method)
def second_method(self, result):
print("Second method received:", result)
# print("Second city", result)
@listen(generate_city)
def generate_fun_fact(self, random_city):
response = self.client.chat.completions.create(
model=self.model,
messages=[
{
"role": "user",
"content": f"Tell me a fun fact about {random_city}",
},
],
)
fun_fact = response.choices[0].message.content
print("---- Fun Fact ----")
print(fun_fact)
async def main():