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

refactor(typespec): Use typespec generated models #766

Merged
merged 9 commits into from
Oct 29, 2024
Merged
4 changes: 2 additions & 2 deletions agents-api/agents_api/activities/execute_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from beartype import beartype
from temporalio import activity

from ..autogen.openapi_model import IntegrationDef
from ..autogen.openapi_model import BaseIntegrationDef
from ..clients import integrations
from ..common.protocol.tasks import StepContext
from ..common.storage_handler import auto_blob_store
Expand All @@ -16,7 +16,7 @@
async def execute_integration(
context: StepContext,
tool_name: str,
integration: IntegrationDef,
integration: BaseIntegrationDef,
arguments: dict[str, Any],
setup: dict[str, Any] = {},
) -> Any:
Expand Down
15 changes: 5 additions & 10 deletions agents-api/agents_api/autogen/Agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ class Agent(BaseModel):
name: Annotated[
str,
Field(
"",
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = ""
"""
Name of the agent
"""
Expand Down Expand Up @@ -66,11 +65,10 @@ class CreateAgentRequest(BaseModel):
name: Annotated[
str,
Field(
"",
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = ""
"""
Name of the agent
"""
Expand Down Expand Up @@ -101,11 +99,10 @@ class CreateOrUpdateAgentRequest(CreateAgentRequest):
name: Annotated[
str,
Field(
"",
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = ""
"""
Name of the agent
"""
Expand Down Expand Up @@ -139,11 +136,10 @@ class PatchAgentRequest(BaseModel):
name: Annotated[
str,
Field(
"",
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = ""
"""
Name of the agent
"""
Expand Down Expand Up @@ -177,11 +173,10 @@ class UpdateAgentRequest(BaseModel):
name: Annotated[
str,
Field(
"",
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = ""
"""
Name of the agent
"""
Expand Down
82 changes: 41 additions & 41 deletions agents-api/agents_api/autogen/Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ class BaseChatResponse(BaseModel):
"""
Usage statistics for the completion request
"""
jobs: Annotated[list[UUID], Field([], json_schema_extra={"readOnly": True})]
jobs: Annotated[list[UUID], Field(json_schema_extra={"readOnly": True})] = []
"""
Background job IDs that may have been spawned from this interaction.
"""
docs: Annotated[list[DocReference], Field([], json_schema_extra={"readOnly": True})]
docs: Annotated[
list[DocReference], Field(json_schema_extra={"readOnly": True})
] = []
"""
Documents referenced for this request (for citation purposes).
"""
Expand Down Expand Up @@ -114,20 +116,20 @@ class CompetionUsage(BaseModel):
populate_by_name=True,
)
completion_tokens: Annotated[
int | None, Field(None, json_schema_extra={"readOnly": True})
]
int | None, Field(json_schema_extra={"readOnly": True})
] = None
"""
Number of tokens in the generated completion
"""
prompt_tokens: Annotated[
int | None, Field(None, json_schema_extra={"readOnly": True})
]
int | None, Field(json_schema_extra={"readOnly": True})
] = None
"""
Number of tokens in the prompt
"""
total_tokens: Annotated[
int | None, Field(None, json_schema_extra={"readOnly": True})
]
total_tokens: Annotated[int | None, Field(json_schema_extra={"readOnly": True})] = (
None
)
"""
Total number of tokens used in the request (prompt + completion)
"""
Expand Down Expand Up @@ -186,7 +188,7 @@ class Delta(BaseModel):
"""
Name
"""
continue_: Annotated[StrictBool | None, Field(None, alias="continue")]
continue_: Annotated[StrictBool | None, Field(alias="continue")] = None
"""
Whether to continue this message or return a new one
"""
Expand Down Expand Up @@ -244,7 +246,7 @@ class Message(BaseModel):
"""
Name
"""
continue_: Annotated[StrictBool | None, Field(None, alias="continue")]
continue_: Annotated[StrictBool | None, Field(alias="continue")] = None
"""
Whether to continue this message or return a new one
"""
Expand Down Expand Up @@ -285,18 +287,18 @@ class MessageModel(BaseModel):
Name
"""
tool_calls: Annotated[
list[ChosenToolCall] | None, Field([], json_schema_extra={"readOnly": True})
]
list[ChosenToolCall] | None, Field(json_schema_extra={"readOnly": True})
] = []
"""
Tool calls generated by the model.
"""
created_at: Annotated[
AwareDatetime | None, Field(None, json_schema_extra={"readOnly": True})
]
AwareDatetime | None, Field(json_schema_extra={"readOnly": True})
] = None
"""
When this resource was created as UTC date-time
"""
id: Annotated[UUID | None, Field(None, json_schema_extra={"readOnly": True})]
id: Annotated[UUID | None, Field(json_schema_extra={"readOnly": True})] = None


class MultipleChatOutput(BaseChatOutput):
Expand All @@ -316,19 +318,19 @@ class OpenAISettings(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
frequency_penalty: Annotated[float | None, Field(None, ge=-2.0, le=2.0)]
frequency_penalty: Annotated[float | None, Field(ge=-2.0, le=2.0)] = None
"""
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
"""
presence_penalty: Annotated[float | None, Field(None, ge=-2.0, le=2.0)]
presence_penalty: Annotated[float | None, Field(ge=-2.0, le=2.0)] = None
"""
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
"""
temperature: Annotated[float | None, Field(None, ge=0.0, le=5.0)]
temperature: Annotated[float | None, Field(ge=0.0, le=5.0)] = None
"""
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
"""
top_p: Annotated[float | None, Field(None, ge=0.0, le=1.0)]
top_p: Annotated[float | None, Field(ge=0.0, le=1.0)] = None
"""
Defaults to 1 An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
"""
Expand Down Expand Up @@ -386,7 +388,7 @@ class ChatInput(ChatInputData):
model_config = ConfigDict(
populate_by_name=True,
)
remember: Annotated[StrictBool, Field(False, json_schema_extra={"readOnly": True})]
remember: Annotated[StrictBool, Field(json_schema_extra={"readOnly": True})] = False
"""
DISABLED: Whether this interaction should form new memories or not (will be enabled in a future release)
"""
Expand All @@ -401,27 +403,26 @@ class ChatInput(ChatInputData):
model: Annotated[
str | None,
Field(
None,
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = None
"""
Identifier of the model to be used
"""
stream: StrictBool = False
"""
Indicates if the server should stream the response as it's generated
"""
stop: Annotated[list[str], Field([], max_length=4)]
stop: Annotated[list[str], Field(max_length=4)] = []
"""
Up to 4 sequences where the API will stop generating further tokens.
"""
seed: Annotated[int | None, Field(None, ge=-1, le=1000)]
seed: Annotated[int | None, Field(ge=-1, le=1000)] = None
"""
If specified, the system will make a best effort to sample deterministically for that particular seed value
"""
max_tokens: Annotated[int | None, Field(None, ge=1)]
max_tokens: Annotated[int | None, Field(ge=1)] = None
"""
The maximum number of tokens to generate in the chat completion
"""
Expand All @@ -439,31 +440,31 @@ class ChatInput(ChatInputData):
"""
Agent ID of the agent to use for this interaction. (Only applicable for multi-agent sessions)
"""
repetition_penalty: Annotated[float | None, Field(None, ge=0.0, le=2.0)]
repetition_penalty: Annotated[float | None, Field(ge=0.0, le=2.0)] = None
"""
Number between 0 and 2.0. 1.0 is neutral and values larger than that penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
"""
length_penalty: Annotated[float | None, Field(None, ge=0.0, le=2.0)]
length_penalty: Annotated[float | None, Field(ge=0.0, le=2.0)] = None
"""
Number between 0 and 2.0. 1.0 is neutral and values larger than that penalize number of tokens generated.
"""
min_p: Annotated[float | None, Field(None, ge=0.0, le=1.0)]
min_p: Annotated[float | None, Field(ge=0.0, le=1.0)] = None
"""
Minimum probability compared to leading token to be considered
"""
frequency_penalty: Annotated[float | None, Field(None, ge=-2.0, le=2.0)]
frequency_penalty: Annotated[float | None, Field(ge=-2.0, le=2.0)] = None
"""
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
"""
presence_penalty: Annotated[float | None, Field(None, ge=-2.0, le=2.0)]
presence_penalty: Annotated[float | None, Field(ge=-2.0, le=2.0)] = None
"""
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
"""
temperature: Annotated[float | None, Field(None, ge=0.0, le=5.0)]
temperature: Annotated[float | None, Field(ge=0.0, le=5.0)] = None
"""
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
"""
top_p: Annotated[float | None, Field(None, ge=0.0, le=1.0)]
top_p: Annotated[float | None, Field(ge=0.0, le=1.0)] = None
"""
Defaults to 1 An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
"""
Expand All @@ -477,15 +478,15 @@ class DefaultChatSettings(OpenAISettings):
model_config = ConfigDict(
populate_by_name=True,
)
repetition_penalty: Annotated[float | None, Field(None, ge=0.0, le=2.0)]
repetition_penalty: Annotated[float | None, Field(ge=0.0, le=2.0)] = None
"""
Number between 0 and 2.0. 1.0 is neutral and values larger than that penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
"""
length_penalty: Annotated[float | None, Field(None, ge=0.0, le=2.0)]
length_penalty: Annotated[float | None, Field(ge=0.0, le=2.0)] = None
"""
Number between 0 and 2.0. 1.0 is neutral and values larger than that penalize number of tokens generated.
"""
min_p: Annotated[float | None, Field(None, ge=0.0, le=1.0)]
min_p: Annotated[float | None, Field(ge=0.0, le=1.0)] = None
"""
Minimum probability compared to leading token to be considered
"""
Expand All @@ -498,27 +499,26 @@ class ChatSettings(DefaultChatSettings):
model: Annotated[
str | None,
Field(
None,
max_length=120,
pattern="^[\\p{L}\\p{Nl}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]+[\\p{ID_Start}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}\\p{Pattern_Syntax}\\p{Pattern_White_Space}]*$",
),
]
] = None
"""
Identifier of the model to be used
"""
stream: StrictBool = False
"""
Indicates if the server should stream the response as it's generated
"""
stop: Annotated[list[str], Field([], max_length=4)]
stop: Annotated[list[str], Field(max_length=4)] = []
"""
Up to 4 sequences where the API will stop generating further tokens.
"""
seed: Annotated[int | None, Field(None, ge=-1, le=1000)]
seed: Annotated[int | None, Field(ge=-1, le=1000)] = None
"""
If specified, the system will make a best effort to sample deterministically for that particular seed value
"""
max_tokens: Annotated[int | None, Field(None, ge=1)]
max_tokens: Annotated[int | None, Field(ge=1)] = None
"""
The maximum number of tokens to generate in the chat completion
"""
Expand Down
6 changes: 3 additions & 3 deletions agents-api/agents_api/autogen/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ResourceCreatedResponse(BaseModel):
"""
When this resource was created as UTC date-time
"""
jobs: Annotated[list[UUID], Field([], json_schema_extra={"readOnly": True})]
jobs: Annotated[list[UUID], Field(json_schema_extra={"readOnly": True})] = []
"""
IDs (if any) of jobs created as part of this request
"""
Expand All @@ -86,7 +86,7 @@ class ResourceDeletedResponse(BaseModel):
"""
When this resource was deleted as UTC date-time
"""
jobs: Annotated[list[UUID], Field([], json_schema_extra={"readOnly": True})]
jobs: Annotated[list[UUID], Field(json_schema_extra={"readOnly": True})] = []
"""
IDs (if any) of jobs created as part of this request
"""
Expand All @@ -104,7 +104,7 @@ class ResourceUpdatedResponse(BaseModel):
"""
When this resource was updated as UTC date-time
"""
jobs: Annotated[list[UUID], Field([], json_schema_extra={"readOnly": True})]
jobs: Annotated[list[UUID], Field(json_schema_extra={"readOnly": True})] = []
"""
IDs (if any) of jobs created as part of this request
"""
Expand Down
12 changes: 6 additions & 6 deletions agents-api/agents_api/autogen/Docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BaseDocSearchRequest(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
)
limit: Annotated[int, Field(10, ge=1, le=50)]
limit: Annotated[int, Field(ge=1, le=50)] = 10
lang: Literal["en-US"] = "en-US"
"""
The language to be used for text-only search. Support for other languages coming soon.
Expand Down Expand Up @@ -64,8 +64,8 @@ class Doc(BaseModel):
"""
embeddings: Annotated[
list[float] | list[list[float]] | None,
Field(None, json_schema_extra={"readOnly": True}),
]
Field(json_schema_extra={"readOnly": True}),
] = None
"""
Embeddings for the document
"""
Expand Down Expand Up @@ -124,11 +124,11 @@ class HybridDocSearchRequest(BaseDocSearchRequest):
model_config = ConfigDict(
populate_by_name=True,
)
confidence: Annotated[float, Field(0.5, ge=0.0, le=1.0)]
confidence: Annotated[float, Field(ge=0.0, le=1.0)] = 0.5
"""
The confidence cutoff level
"""
alpha: Annotated[float, Field(0.75, ge=0.0, le=1.0)]
alpha: Annotated[float, Field(ge=0.0, le=1.0)] = 0.75
"""
The weight to apply to BM25 vs Vector search results. 0 => pure BM25; 1 => pure vector;
"""
Expand Down Expand Up @@ -192,7 +192,7 @@ class VectorDocSearchRequest(BaseDocSearchRequest):
model_config = ConfigDict(
populate_by_name=True,
)
confidence: Annotated[float, Field(0.5, ge=0.0, le=1.0)]
confidence: Annotated[float, Field(ge=0.0, le=1.0)] = 0.5
"""
The confidence cutoff level
"""
Expand Down
Loading
Loading