Skip to content

fix. use agent_id instead of assistant_id. use agents' API to get mes… #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions app/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,17 @@ def prompt(req: func.HttpRequest) -> func.HttpResponse:
logging.info(f"Created message, message ID: {message.id}")

# Run the agent
run = project_client.agents.create_run(thread_id=thread.id, assistant_id=agent.id)
# Monitor and process the run status
while run.status in ["queued", "in_progress", "requires_action"]:
time.sleep(1)
run = project_client.agents.get_run(thread_id=thread.id, run_id=run.id)

if run.status not in ["queued", "in_progress", "requires_action"]:
break

logging.info(f"Run finished with status: {run.status}")

if run.status == "failed":
logging.error(f"Run failed: {run.last_error}")

# Get messages from the assistant thread
messages = project_client.agents.get_messages(thread_id=thread.id)
run = project_client.agents.create_and_process_run(
thread_id=thread.id, agent_id=agent.id
)
messages = project_client.agents.list_messages(thread_id=thread.id)
logging.info(f"Messages: {messages}")

# Get the last message from the assistant
last_msg = messages.get_last_text_message_by_sender("assistant")
if last_msg:
logging.info(f"Last Message: {last_msg.text.value}")

textvalue = messages.data[0].content[0].text.value
# Delete the agent once done
project_client.agents.delete_agent(agent.id)
print("Deleted agent")

return func.HttpResponse(last_msg.text.value)
return func.HttpResponse(textvalue)

# Function to get the weather
@app.function_name(name="GetWeather")
Expand Down