Azure AI Assistants (preview) -> how to call Assistants in API in our function/app - "once created in playground" -> i.e. write once, call anywhere

GenixPRO 36 Reputation points
2024-09-12T22:27:01.4033333+00:00

Hi. we've created a few Assistants in Assistants playground. We've their IDs. However can't find API call format to call Assistants using Assistant_ID. The API quickstart is focused on creating new assistant.

Qn: Can we "write once, call anywhere" AI Assistants? If yes, how? We don't see any parameter in API call to indicate already created Assistant_ID. Will JSON response of such API return thread_ID?

Thanks.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,080 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 24,300 Reputation points Microsoft Employee
    2024-09-13T02:16:40.36+00:00

    @GenixPRO Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    .

    Yes, you can “write once, call anywhere” with Azure AI Assistants. See this article.

    .

    Once you’ve created your Assistants in the playground and have their IDs, you can call them using the Assistants API. Here’s how you can do it:

    1. Initialize the Assistant: Use the assistant_id to initialize the Assistant in your application. For example, in Python, you can use the following code snippet:

    User's image

    1. Create a Thread: To interact with the Assistant, you need to create a thread. This thread will manage the conversation context.
    thread = client.beta.threads.create(assistant_id=assistant.id)
    
    
    1. Run the Assistant: Once the thread is created, you can start a run to get responses from the Assistant.
    run = client.beta.threads.runs.create(thread_id=thread.id, assistant_id=assistant.id)
    
    
    1. Handle Responses: The JSON response from the API will include a thread_id, which you can use to continue the conversation in subsequent API calls.

    For more detailed information, you can refer to the Azure OpenAI Assistants documentation

    .

    Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.