Skip to content

Commit

Permalink
adds support for anthropic models to Explorer assistant (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrabach authored Dec 1, 2024
1 parent c7d785f commit 820e4d8
Show file tree
Hide file tree
Showing 79 changed files with 6,844 additions and 869 deletions.
8 changes: 8 additions & 0 deletions assistants/explorer-assistant/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
"**/__pycache__": true
},
// For use with optional extension: "streetsidesoftware.code-spell-checker"
"cSpell.ignorePaths": [
".venv",
"node_modules",
"package-lock.json",
"settings.json",
"uv.lock"
],
"cSpell.words": [
"Codespaces",
"contentsafety",
Expand All @@ -58,6 +65,7 @@
"pdfplumber",
"pydantic",
"pyproject",
"pyright",
"tiktoken",
"updown",
"virtualenvs"
Expand Down
602 changes: 29 additions & 573 deletions assistants/explorer-assistant/assistant/chat.py

Large diffs are not rendered by default.

61 changes: 3 additions & 58 deletions assistants/explorer-assistant/assistant/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Annotated

import openai_client
from assistant_extensions.ai_clients.config import AIClientConfig
from assistant_extensions.artifacts import ArtifactsConfigModel
from assistant_extensions.attachments import AttachmentsConfigModel
from assistant_extensions.workflows import WorkflowsConfigModel
from content_safety.evaluators import CombinedContentSafetyEvaluatorConfig
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, Field
from semantic_workbench_assistant.config import UISchema

from . import helpers
Expand Down Expand Up @@ -81,54 +81,6 @@ class HighTokenUsageWarning(BaseModel):
] = 90


class RequestConfig(BaseModel):
model_config = ConfigDict(
title="Response Generation",
json_schema_extra={
"required": ["max_tokens", "response_tokens", "openai_model"],
},
)

max_tokens: Annotated[
int,
Field(
title="Max Tokens",
description=(
"The maximum number of tokens to use for both the prompt and response. Current max supported by OpenAI"
" is 128k tokens, but varies by model [https://platform.openai.com/docs/models]"
"(https://platform.openai.com/docs/models)."
),
),
UISchema(enable_markdown_in_description=True),
] = 128_000

response_tokens: Annotated[
int,
Field(
title="Response Tokens",
description=(
"The number of tokens to use for the response, will reduce the number of tokens available for the"
" prompt. Current max supported by OpenAI is 4096 tokens [https://platform.openai.com/docs/models]"
"(https://platform.openai.com/docs/models)."
),
),
UISchema(enable_markdown_in_description=True),
] = 4_048

openai_model: Annotated[
str,
Field(title="OpenAI Model", description="The OpenAI model to use for generating responses."),
] = "gpt-4o"

is_reasoning_model: Annotated[
bool,
Field(
title="Is Reasoning Model (o1-preview, o1-mini, etc)",
description="Experimental: enable support for reasoning models such as o1-preview, o1-mini, etc.",
),
] = False


# the workbench app builds dynamic forms based on the configuration model and UI schema
class AssistantConfigModel(BaseModel):
enable_debug_output: Annotated[
Expand Down Expand Up @@ -199,14 +151,7 @@ class AssistantConfigModel(BaseModel):
),
] = HighTokenUsageWarning()

request_config: Annotated[
RequestConfig,
Field(
title="Request Configuration",
),
] = RequestConfig()

service_config: openai_client.ServiceConfig
ai_client_config: AIClientConfig

content_safety_config: Annotated[
CombinedContentSafetyEvaluatorConfig,
Expand Down
3 changes: 3 additions & 0 deletions assistants/explorer-assistant/assistant/response/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .response import respond_to_conversation

__all__ = ["respond_to_conversation"]
37 changes: 37 additions & 0 deletions assistants/explorer-assistant/assistant/response/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Any, Protocol, Sequence

from assistant_extensions.ai_clients.model import CompletionMessage
from attr import dataclass
from semantic_workbench_api_model.workbench_model import (
MessageType,
)


@dataclass
class NumberTokensResult:
count: int
metadata: dict[str, Any]
metadata_key: str


@dataclass
class ResponseResult:
content: str | None
message_type: MessageType
metadata: dict[str, Any]
completion_total_tokens: int


class ResponseProvider(Protocol):
async def get_response(
self,
messages: list[CompletionMessage],
metadata_key: str,
) -> ResponseResult: ...

async def num_tokens_from_messages(
self,
messages: Sequence[CompletionMessage],
model: str,
metadata_key: str,
) -> NumberTokensResult: ...
Loading

0 comments on commit 820e4d8

Please sign in to comment.