Skip to content

Re-use httpx client from assistants #575

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

Merged
merged 5 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
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
25 changes: 3 additions & 22 deletions assistants/project-assistant/assistant/conversation_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@

from typing import Any, Optional, Tuple

import semantic_workbench_api_model.workbench_service_client as wsc
from semantic_workbench_api_model.workbench_service_client import ConversationAPIClient
from semantic_workbench_assistant import settings
from semantic_workbench_assistant.assistant_app import ConversationContext
from semantic_workbench_assistant.storage import read_model

from .logging import logger
from .conversation_project_link import ConversationProjectManager
from .logging import logger
from .project_storage import ProjectStorageManager
from .project_storage_models import ConversationRole

Expand All @@ -33,17 +31,7 @@ def get_conversation_client(context: ConversationContext, conversation_id: str)
"""
Gets a client for accessing another conversation.
"""
# Create a client for the target conversation
builder = wsc.WorkbenchServiceClientBuilder(
base_url=str(settings.workbench_service_url),
assistant_service_id=context.assistant._assistant_service_id,
api_key=settings.workbench_service_api_key,
)
client = builder.for_conversation(
assistant_id=context.assistant.id,
conversation_id=conversation_id,
)
return client
return context.for_conversation(conversation_id)._conversation_client

@staticmethod
async def get_coordinator_client_for_project(
Expand Down Expand Up @@ -88,17 +76,10 @@ async def create_temporary_context_for_conversation(
Creates a temporary context for the target conversation ID.
"""
try:
# We'll use the same assistant as in the source context
assistant = source_context.assistant

# Create a temporary context with the same properties as the original
# but pointing to a different conversation

temp_context = ConversationContext(
assistant=assistant,
id=target_conversation_id,
title=source_context.title,
)
temp_context = source_context.for_conversation(target_conversation_id)

return temp_context

Expand Down
2 changes: 1 addition & 1 deletion examples/python/python-01-echo-bot/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "Example of a python Semantic Workbench assistant."
authors = [{ name = "Semantic Workbench Team" }]
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.11,<3.13"
dependencies = ["openai>=1.61.0", "semantic-workbench-assistant>=0.1.0"]

[tool.uv]
Expand Down
50 changes: 1 addition & 49 deletions examples/python/python-01-echo-bot/uv.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/python/python-02-simple-chatbot/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "Exploration of a python Semantic Workbench OpenAI assistant."
authors = [{ name = "Semantic Workbench Team" }]
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.11,<3.13"
dependencies = [
"openai>=1.61.0",
"tiktoken>=0.8.0",
Expand Down
243 changes: 2 additions & 241 deletions examples/python/python-02-simple-chatbot/uv.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "Exploration of a python Semantic Workbench assistant that supports multiple AI models."
authors = [{ name = "Semantic Workbench Team" }]
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.11,<3.13"
dependencies = [
"anthropic>=0.34.2",
"google-genai>=1.2.0",
Expand Down
247 changes: 2 additions & 245 deletions examples/python/python-03-multimodel-chatbot/uv.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, AsyncGenerator, AsyncIterator, Callable, Iterable
from unittest import mock

import httpx
import pytest
from assistant_extensions.attachments import AttachmentsConfigModel, AttachmentsExtension
from llm_client.model import (
Expand Down Expand Up @@ -104,20 +105,23 @@ async def test_get_completion_messages_for_attachments(
) -> None:
mock_assistant_app = mock.MagicMock(spec=AssistantAppProtocol)

assistant_id = uuid.uuid4()

mock_conversation_context = mock.MagicMock(
spec=ConversationContext(
id="conversation_id",
title="conversation_title",
assistant=AssistantContext(
id="assistant_id",
id=str(assistant_id),
name="assistant_name",
_assistant_service_id="assistant_id",
_template_id="",
),
httpx_client=httpx.AsyncClient(),
)
)
mock_conversation_context.id = "conversation_id"
mock_conversation_context.assistant.id = "assistant_id"
mock_conversation_context.assistant.id = str(assistant_id)

mock_conversation_context.list_files.return_value = FileList(
files=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ async def duplicate_conversation(
conversation_id = response.conversation_ids[0]

# create a new conversation context
workflow_context = ConversationContext(
id=str(conversation_id),
title=title,
assistant=context.assistant,
)
workflow_context = context.for_conversation(str(conversation_id))

# send link to chat for the new conversation
await context.send_messages(
Expand Down
2 changes: 1 addition & 1 deletion libraries/python/content-safety/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "Content Safety for Semantic Workbench Assistants"
authors = [{ name = "Semantic Workbench Team" }]
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.11,<3.13"
dependencies = [
"azure-ai-contentsafety>=1.0.0",
"azure-core[aio]>=1.30.0",
Expand Down
Loading