Skip to content
Merged
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
15 changes: 2 additions & 13 deletions sources/platform/integrations/ai/openai_assistants.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ Import all required packages:

import json
import time
from typing import TYPE_CHECKING

from apify_client import ApifyClient
from openai import OpenAI, Stream
from openai.types.beta.threads.run_submit_tool_outputs_params import ToolOutput

if TYPE_CHECKING:
from openai.types.beta import AssistantStreamEvent
from openai.types.beta.threads import Run
```

Find your [Apify API token](https://console.apify.com/account/integrations) and [OpenAI API key](https://platform.openai.com/account/api-keys) and initialize OpenAI and Apify clients:
Expand Down Expand Up @@ -134,7 +129,7 @@ This function will trigger the RAG-Web-Browser to fetch the search data and subm
Let's implement the `submit_tool_outputs` function:

```python
def submit_tool_outputs(run_: Run) -> Run | Stream[AssistantStreamEvent]:
def submit_tool_outputs(run_):
""" Submit tool outputs to continue the run """
tool_output = []
for tool in run_.required_action.submit_tool_outputs.tool_calls:
Expand Down Expand Up @@ -178,15 +173,11 @@ The latest news on LLM is as follows:

```python
import json
from typing import TYPE_CHECKING

from apify_client import ApifyClient
from openai import OpenAI, Stream
from openai.types.beta.threads.run_submit_tool_outputs_params import ToolOutput

if TYPE_CHECKING:
from openai.types.beta import AssistantStreamEvent
from openai.types.beta.threads import Run

client = OpenAI(api_key="YOUR-OPENAI-API-KEY")
apify_client = ApifyClient("YOUR-APIFY-API-TOKEN")
Expand Down Expand Up @@ -215,8 +206,6 @@ rag_web_browser_function = {
}
}

my_assistant = client.beta.assistants.retrieve("asst_7GXx3q9lWLmhSf9yexA7J1WX")


def call_rag_web_browser(query: str, max_results: int) -> list[dict]:
"""
Expand All @@ -227,7 +216,7 @@ def call_rag_web_browser(query: str, max_results: int) -> list[dict]:
return apify_client.dataset(actor_call["defaultDatasetId"]).list_items().items


def submit_tool_outputs(run_: Run) -> Run | Stream[AssistantStreamEvent]:
def submit_tool_outputs(run_):
""" Submit tool outputs to continue the run """
tool_output = []
for tool in run_.required_action.submit_tool_outputs.tool_calls:
Expand Down