Skip to content

Commit

Permalink
Add tooltip to fields (#233)
Browse files Browse the repository at this point in the history
* Add tooltip to fields

* Refactoring

* Update docs

* Polishing
  • Loading branch information
harishmohanraj authored Sep 17, 2024
1 parent 438b7c1 commit 15192c5
Show file tree
Hide file tree
Showing 25 changed files with 321 additions and 65 deletions.
1 change: 1 addition & 0 deletions docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ search:
- [WebSurferAnswer](api/fastagency/studio/models/agents/web_surfer_autogen/WebSurferAnswer.md)
- [WebSurferChat](api/fastagency/studio/models/agents/web_surfer_autogen/WebSurferChat.md)
- base
- [Field](api/fastagency/studio/models/base/Field.md)
- [Model](api/fastagency/studio/models/base/Model.md)
- [ModelTypeFinder](api/fastagency/studio/models/base/ModelTypeFinder.md)
- [ObjectReference](api/fastagency/studio/models/base/ObjectReference.md)
Expand Down
11 changes: 11 additions & 0 deletions docs/docs/en/api/fastagency/studio/models/base/Field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# 0.5 - API
# 2 - Release
# 3 - Contributing
# 5 - Template Page
# 10 - Default
search:
boost: 0.5
---

::: fastagency.studio.models.base.Field
5 changes: 3 additions & 2 deletions fastagency/studio/models/agents/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from uuid import UUID

import autogen
from pydantic import Field

from ....api.openapi import OpenAPI
from ..base import Field
from ..registry import register
from .base import AgentBaseModel

Expand All @@ -14,7 +14,8 @@ class AssistantAgent(AgentBaseModel):
system_message: Annotated[
str,
Field(
description="The system message of the agent. This message is used to inform the agent about his role in the conversation"
description="The system message of the agent. This message is used to inform the agent about his role in the conversation",
tooltip_message="The system message defines the agent's role and influences its responses. For example, telling the agent 'You are an expert in travel advice' will make its responses focus on travel.",
),
] = "You are a helpful assistant. After you successfully answer all questions and there are no new questions asked after your response (e.g. there is no specific direction or question asked after you give a response), terminate the chat by outputting 'TERMINATE' (IMPORTANT: use all caps)"

Expand Down
7 changes: 5 additions & 2 deletions fastagency/studio/models/agents/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import Annotated, Optional, Union
from uuid import UUID

from pydantic import Field
from typing_extensions import TypeAlias

from fastagency.api.openapi import OpenAPI

from ..base import Model
from ..base import Field, Model
from ..registry import Registry
from ..toolboxes.toolbox import ToolboxRef

Expand All @@ -24,6 +23,7 @@ class AgentBaseModel(Model):
Field(
title="LLM",
description="LLM used by the agent for producing responses",
tooltip_message="Choose the LLM the agent will use to generate responses.",
),
]

Expand All @@ -32,6 +32,7 @@ class AgentBaseModel(Model):
Field(
title="Toolbox",
description="Toolbox used by the agent for producing responses",
tooltip_message="Choose the toolbox that the agent will use automatically when needed to solve user queries.",
),
] = None

Expand All @@ -40,6 +41,7 @@ class AgentBaseModel(Model):
Field(
title="Toolbox",
description="Toolbox used by the agent for producing responses",
tooltip_message="Choose the toolbox that the agent will use automatically when needed to solve user queries.",
),
] = None

Expand All @@ -48,6 +50,7 @@ class AgentBaseModel(Model):
Field(
title="Toolbox",
description="Toolbox used by the agent for producing responses",
tooltip_message="Choose the toolbox that the agent will use automatically when needed to solve user queries.",
),
] = None

Expand Down
6 changes: 3 additions & 3 deletions fastagency/studio/models/agents/user_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from uuid import UUID

import autogen
from pydantic import Field

from ....api.openapi import OpenAPI
from ..base import Model
from ..base import Field, Model
from ..registry import register


Expand All @@ -14,7 +13,8 @@ class UserProxyAgent(Model):
max_consecutive_auto_reply: Annotated[
Optional[int],
Field(
description="The maximum number of consecutive auto-replies the agent can make"
description="The maximum number of consecutive auto-replies the agent can make",
tooltip_message="Set the maximum number of consecutive auto replies the agent can make before requiring human approval. A higher value gives the agent more autonomy, while leaving it blank prompts permission for each reply. For example, if you set this to 2, the agent will reply twice and then require human approval before replying again.",
),
] = None

Expand Down
25 changes: 20 additions & 5 deletions fastagency/studio/models/agents/web_surfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@
from asyncer import syncify
from autogen.agentchat import AssistantAgent as AutoGenAssistantAgent
from autogen.agentchat import ConversableAgent as AutoGenConversableAgent
from pydantic import Field
from typing_extensions import TypeAlias

from fastagency.studio.models.agents.web_surfer_autogen import WebSurferChat

from ..base import Model
from ..base import Field, Model
from ..registry import register
from .base import AgentBaseModel, llm_type_refs


@register("secret")
class BingAPIKey(Model):
api_key: Annotated[str, Field(title="API Key", description="The API Key from Bing")]
api_key: Annotated[
str,
Field(
title="API Key",
description="The API Key from Bing",
tooltip_message="The API key specified here will be used to authenticate requests to Bing services.",
),
]

@classmethod
async def create_autogen(cls, model_id: UUID, user_id: UUID, **kwargs: Any) -> str:
Expand Down Expand Up @@ -87,14 +93,23 @@ class WebSurferAgent(AgentBaseModel):
Field(
title="Summarizer LLM",
description="This LLM will be used to generated summary of all pages visited",
tooltip_message="Select the summarizer LLM, which is used for generating precise and accurate summaries of web pages, while the LLM chosen above is used for handling regular web searches.",
),
]
viewport_size: Annotated[
int, Field(description="The viewport size of the browser")
int,
Field(
description="The viewport size of the browser",
tooltip_message="Viewport size refers to the visible area of a webpage in the browser. Default is 4096. Modify only if a custom size is needed.",
),
] = 4096
bing_api_key: Annotated[
Optional[BingAPIKeyRef],
Field(title="Bing API Key", description="The Bing API key for the browser"),
Field(
title="Bing API Key",
description="The Bing API key for the browser",
tooltip_message="Choose a Bing API key to allow the browser to access Bing's search and data services, improving information retrieval.",
),
] = None

@classmethod
Expand Down
62 changes: 53 additions & 9 deletions fastagency/studio/models/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from abc import ABC, abstractmethod
from typing import Annotated, Any, Literal, Optional, Protocol, Type, TypeVar
from typing import (
Annotated,
Any,
Literal,
Optional,
Protocol,
Type,
TypeVar,
Union,
)
from uuid import UUID

from pydantic import BaseModel, Field, create_model, model_validator
from pydantic import BaseModel, create_model, model_validator
from pydantic import Field as PydanticField
from typing_extensions import TypeAlias

from ..db.base import DefaultDB
Expand All @@ -14,6 +24,7 @@
"create_reference_model",
"get_reference_model",
"Model",
"Field",
]


Expand All @@ -22,7 +33,9 @@

# abstract class
class Model(BaseModel, ABC):
name: Annotated[str, Field(..., description="The name of the item", min_length=1)]
name: Annotated[
str, PydanticField(..., description="The name of the item", min_length=1)
]
_reference_model: "Optional[Type[ObjectReference]]" = None

@classmethod
Expand All @@ -46,9 +59,11 @@ async def from_db(cls: type[T], model_id: UUID) -> T:


class ObjectReference(BaseModel):
type: Annotated[str, Field(description="The name of the type of the data")] = ""
name: Annotated[str, Field(description="The name of the data")] = ""
uuid: Annotated[UUID, Field(description="The unique identifier")]
type: Annotated[
str, PydanticField(description="The name of the type of the data")
] = ""
name: Annotated[str, PydanticField(description="The name of the data")] = ""
uuid: Annotated[UUID, PydanticField(description="The unique identifier")]

_data_class: Optional["Type[Model]"] = None

Expand Down Expand Up @@ -113,16 +128,21 @@ def create_reference_model(
f"{model_type_name}Ref",
type=(
Annotated[ # type: ignore[valid-type]
LiteralType, Field(description="The name of the type of the data")
LiteralType,
PydanticField(description="The name of the type of the data"),
],
type_name,
),
name=(
Annotated[LiteralModelName, Field(description="The name of the data")],
Annotated[
LiteralModelName, PydanticField(description="The name of the data")
],
model_type_name,
),
uuid=(
Annotated[UUID, Field(description="The unique identifier", title="UUID")],
Annotated[
UUID, PydanticField(description="The unique identifier", title="UUID")
],
...,
),
__base__=ObjectReference,
Expand All @@ -148,3 +168,27 @@ def get_reference_model(model: type[BaseModel]) -> type[ObjectReference]:
elif hasattr(model, "_reference_model"):
return model._reference_model # type: ignore[attr-defined,no-any-return]
raise ValueError(f"Class '{model.__name__}' is not and does not have a reference")


def Field( # noqa: N802
default: Any = ...,
*,
description: Optional[str] = None,
tooltip_message: Optional[str] = None,
immutable_after_creation: bool = False,
**kwargs: Any,
) -> Any:
metadata: dict[str, Union[str, bool]] = {}

if tooltip_message is not None:
metadata["tooltip_message"] = tooltip_message
if immutable_after_creation:
metadata["immutable_after_creation"] = immutable_after_creation

# Create json_schema_extra only if we have metadata
if metadata:
kwargs["json_schema_extra"] = {"metadata": metadata}

return PydanticField( # type: ignore[pydantic-field]
default, description=description, **kwargs
)
22 changes: 15 additions & 7 deletions fastagency/studio/models/deployments/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from typing import Annotated, Any, Union
from uuid import UUID

from pydantic import Field, field_validator
from pydantic import field_validator
from typing_extensions import TypeAlias

from ..base import Model
from ..base import Field, Model
from ..registry import Registry
from ..secrets.fly_token import FlyToken
from ..secrets.github_token import GitHubToken
Expand All @@ -29,7 +29,10 @@ class Deployment(Model):
name: Annotated[
str,
Field(
..., description="The application name to use on the website.", min_length=1
...,
description="The name of the SaaS application.",
min_length=1,
tooltip_message="The application name to be used in the deployed SaaS application.",
),
]

Expand All @@ -39,7 +42,8 @@ class Deployment(Model):
...,
description="The name of the GitHub repository.",
min_length=1,
json_schema_extra={"metadata": {"immutable_after_creation": True}},
immutable_after_creation=True,
tooltip_message="The GitHub repository to be created. If the name contains spaces or special characters, GitHub will adjust it according to its naming rules. A random suffix will be added if the repository name already exists.",
),
]

Expand All @@ -50,7 +54,8 @@ class Deployment(Model):
description="The name of the Fly.io application.",
min_length=1,
max_length=30,
json_schema_extra={"metadata": {"immutable_after_creation": True}},
immutable_after_creation=True,
tooltip_message="The Fly.io application. This will be used to create and deploy your React, Node.js, and PostgreSQL apps to Fly.io.",
),
]

Expand All @@ -59,22 +64,25 @@ class Deployment(Model):
Field(
title="Team Name",
description="The team that is used in the deployment",
tooltip_message="Choose the team to be used for deployment. User messages are sent to the Initial agent of the chosen team, and the agent's responses are sent back to the user. This field can be updated anytime to switch teams, with changes reflected in real-time in your deployments.",
),
]
gh_token: Annotated[
GitHubTokenRef,
Field(
title="GH Token",
description="The GitHub token to use for creating a new repository",
json_schema_extra={"metadata": {"immutable_after_creation": True}},
immutable_after_creation=True,
tooltip_message="Choose the GitHub token used for authenticating and managing access to your GitHub account.",
),
]
fly_token: Annotated[
FlyTokenRef,
Field(
title="Fly Token",
description="The Fly.io token to use for deploying the deployment",
json_schema_extra={"metadata": {"immutable_after_creation": True}},
immutable_after_creation=True,
tooltip_message="Choose the Fly.io token used for authenticating and managing access to your Fly.io account.",
),
]

Expand Down
Loading

0 comments on commit 15192c5

Please sign in to comment.