Skip to content
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

How to use this with Assistants API #24

Open
ArunBalajiR opened this issue Sep 3, 2024 · 1 comment
Open

How to use this with Assistants API #24

ArunBalajiR opened this issue Sep 3, 2024 · 1 comment

Comments

@ArunBalajiR
Copy link

I'm trying to achieve the above in OpenAI Assistants API.

let assistantId = assistantDetails.assistantId;

    // Create a thread using the assistantId
    const thread = await openai.beta.threads.create();

    // Pass in the user question into the existing thread
    await openai.beta.threads.messages.create(thread.id, {
        role: "user",
        content: outputString,
    });

    // Create a run
    const run = await openai.beta.threads.runs.create(thread.id, {
        assistant_id: assistantId,
    });

    // Imediately fetch run-status, which will be "in_progress"
    let runStatus = await openai.beta.threads.runs.retrieve(
        thread.id,
        run.id
    );

    // Get the last assistant message from the messages array
    const messages = await openai.beta.threads.messages.list(thread.id);

    // Find the last message for the current run
    const lastMessageForRun = messages.data
        .filter(
            (message) =>
                message.run_id === run.id && message.role === "assistant"
        )
        .pop();

    let assistanceResponse = lastMessageForRun.content[0].text.value;
    ```
@st3w4r
Copy link
Owner

st3w4r commented Sep 8, 2024

Hi @ArunBalajiR, thanks for using the lib. Could you describe in more detail what you've tried and which part isn't working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants