Spaces:
Sleeping
Sleeping
File size: 1,246 Bytes
f8b585c a14f58f 27c9a2b a14f58f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import asyncio
import nest_asyncio
from agent import agent
nest_asyncio.apply()
# To Run in Terminal
# async def main():
# print("GitHub Agent Ready! Ask questions about Receipts Data")
# print("Type 'quit' to exit.\n")
# history = None
# while True:
# prompt = input("You: ")
# if prompt.lower() in ('quit', 'exit', 'q'):
# break
# result = await agent.run(prompt, message_history=history)
# history = result.all_messages() # Call the method
# print(f"\nAgent: {result.output}\n")
# if __name__ == "__main__":
# asyncio.run(main())
# For Deployment in Production
async def ask_agent(prompt: str, history=None):
"""
Run the agent on a single prompt.
Returns a dict with output and updated history.
"""
result = await agent.run(prompt, message_history=history)
return {"output": result.output, "history": result.all_messages()}
# Helper function to call from synchronous code
# Discarded
# def ask_agent_sync(prompt: str, history=None):
# return asyncio.run(ask_agent(prompt, history))
def ask_agent_sync(prompt: str, history=None):
loop = asyncio.get_event_loop()
return loop.run_until_complete(ask_agent(prompt, history)) |