Skip to content

Commit

Permalink
feat: added more types
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Dec 5, 2024
1 parent 14d71ae commit 129ebf6
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 12 deletions.
31 changes: 28 additions & 3 deletions portkey_ai/api_resources/types/assistant_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,33 @@
"ToolCodeInterpreter",
"ToolRetrieval",
"ToolFunction",
"Tool",
"AssistantTool",
"FunctionDefinition",
"FunctionParameters",
"FileSearch",
"FileSearchTool",
]


class FileSearch(BaseModel, extra="allow"):
max_num_results: Optional[int] = None


class FileSearchTool(BaseModel, extra="allow"):
type: Optional[str] = None
file_search: Optional[FileSearch] = None


FunctionParameters = Dict[str, object]


class FunctionDefinition(BaseModel, extra="allow"):
name: Optional[str] = None
description: Optional[str] = None
parameters: Optional[FunctionParameters] = None
strict: Optional[bool] = None


class ToolCodeInterpreter(BaseModel, extra="allow"):
type: Optional[str] = None

Expand All @@ -26,9 +49,10 @@ class ToolRetrieval(BaseModel, extra="allow"):

class ToolFunction(BaseModel, extra="allow"):
type: Optional[str] = None
function: Optional[FunctionDefinition] = None


Tool = Union[ToolCodeInterpreter, ToolRetrieval, ToolFunction]
AssistantTool = Union[ToolCodeInterpreter, ToolRetrieval, ToolFunction, FileSearchTool]


class Assistant(BaseModel, extra="allow"):
Expand All @@ -41,7 +65,8 @@ class Assistant(BaseModel, extra="allow"):
model: Optional[str] = None
name: Optional[str] = None
object: Optional[str] = None
tools: Optional[List[Tool]]
tools: Optional[List[AssistantTool]] = None
response_format: Optional[Any] = None
_headers: Optional[httpx.Headers] = PrivateAttr()

def __str__(self):
Expand Down
17 changes: 13 additions & 4 deletions portkey_ai/api_resources/types/batches_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@
from .utils import parse_headers
from typing import List, Any
from pydantic import BaseModel, PrivateAttr
from ..._vendor.openai.types.batch_error import BatchError
from ..._vendor.openai.types.batch_request_counts import BatchRequestCounts

__all__ = ["Batch", "BatchList", "Errors"]


class BatchError(BaseModel, extra="allow"):
code: Optional[str] = None
line: Optional[int] = None
message: Optional[str] = None
param: Optional[str] = None


class BatchRequestCounts(BaseModel, extra="allow"):
completed: Optional[int] = None
failed: Optional[int] = None
total: Optional[int] = None


class Errors(BaseModel, extra="allow"):
data: Optional[List[BatchError]] = None

object: Optional[str] = None
"""The object type, which is always `list`."""


class Batch(BaseModel, extra="allow"):
Expand Down
15 changes: 14 additions & 1 deletion portkey_ai/api_resources/types/fine_tuning_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .utils import parse_headers
from typing import List, Any
from pydantic import BaseModel, PrivateAttr
from ..._vendor.openai.types.fine_tuning import FineTuningJobWandbIntegrationObject

__all__ = [
"Error",
Expand All @@ -16,6 +15,8 @@
"Metrics",
"FineTuningJobCheckpoint",
"FineTuningJobCheckpointList",
"FineTuningJobWandbIntegration",
"FineTuningJobWandbIntegrationObject",
]


Expand All @@ -29,6 +30,18 @@ class Hyperparameters(BaseModel, extra="allow"):
n_epochs: Union[str, int]


class FineTuningJobWandbIntegration(BaseModel, extra="allow"):
project: str
entity: Optional[str] = None
name: Optional[str] = None
tags: Optional[List[str]] = None


class FineTuningJobWandbIntegrationObject(BaseModel, extra="allow"):
type: Optional[str] = None
wandb: FineTuningJobWandbIntegration


class FineTuningJob(BaseModel, extra="allow"):
id: str
created_at: int
Expand Down
39 changes: 38 additions & 1 deletion portkey_ai/api_resources/types/thread_run_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from typing import Dict, Literal, Optional, Union
import httpx

from portkey_ai.api_resources.types.assistant_type import AssistantTool
from .utils import parse_headers
from typing import List
from pydantic import BaseModel, PrivateAttr
Expand Down Expand Up @@ -35,6 +37,11 @@
"FunctionToolCall",
"FunctionParameters",
"RunStepList",
"IncompleteDetails",
"AssistantToolChoice",
"AssistantToolChoiceFunction",
"AssistantToolChoiceOption",
"TruncationStrategy",
]


Expand Down Expand Up @@ -163,6 +170,28 @@ class ToolAssistantToolsFunction(BaseModel, extra="allow"):
]


class IncompleteDetails(BaseModel, extra="allow"):
reason: Optional[str] = None


class AssistantToolChoiceFunction(BaseModel, extra="allow"):
name: Optional[str] = None


class AssistantToolChoice(BaseModel, extra="allow"):
type: Optional[str] = None

function: Optional[AssistantToolChoiceFunction] = None


AssistantToolChoiceOption = Union[Optional[str], AssistantToolChoice]


class TruncationStrategy(BaseModel, extra="allow"):
type: Optional[str] = None
last_messages: Optional[int] = None


class Run(BaseModel, extra="allow"):
id: Optional[str] = None
assistant_id: Optional[str] = None
Expand All @@ -181,8 +210,16 @@ class Run(BaseModel, extra="allow"):
started_at: Optional[int] = None
status: Optional[str] = None
thread_id: Optional[str] = None
tools: Optional[List[Tool]]
tools: Optional[List[AssistantTool]]
usage: Optional[Usage] = None
incomplete_details: Optional[IncompleteDetails] = None
max_completion_tokens: Optional[int] = None
max_prompt_tokens: Optional[int] = None
parallel_tool_calls: Optional[bool] = None
tool_choice: Optional[AssistantToolChoiceOption] = None
truncation_strategy: Optional[TruncationStrategy] = None
temperature: Optional[float] = None
top_p: Optional[float] = None
_headers: Optional[httpx.Headers] = PrivateAttr()

def __str__(self):
Expand Down
25 changes: 23 additions & 2 deletions portkey_ai/api_resources/types/thread_type.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import json
from typing import Dict, Optional
from typing import Dict, List, Optional
import httpx
from .utils import parse_headers
from pydantic import BaseModel, PrivateAttr


__all__ = ["Thread", "ThreadDeleted"]
__all__ = [
"Thread",
"ThreadDeleted",
"ToolResources",
"ToolResourcesCodeInterpreter",
"ToolResourcesFileSearch",
]


class ToolResourcesCodeInterpreter(BaseModel, extra="allow"):
file_ids: Optional[List[str]] = None


class ToolResourcesFileSearch(BaseModel, extra="allow"):
vector_store_ids: Optional[List[str]] = None


class ToolResources(BaseModel, extra="allow"):
code_interpreter: Optional[ToolResourcesCodeInterpreter] = None

file_search: Optional[ToolResourcesFileSearch] = None


class Thread(BaseModel, extra="allow"):
id: Optional[str] = None
created_at: Optional[int] = None
metadata: Optional[object] = None
object: Optional[str] = None
tool_resources: Optional[ToolResources] = None
_headers: Optional[httpx.Headers] = PrivateAttr()

def __str__(self):
Expand Down
12 changes: 11 additions & 1 deletion portkey_ai/api_resources/types/upload_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
from typing import Dict, Literal, Optional
import httpx

from portkey_ai._vendor.openai.types.file_object import FileObject
from .utils import parse_headers
from pydantic import BaseModel, PrivateAttr


class FileObject(BaseModel, extra="allow"):
id: Optional[str] = None
bytes: Optional[int] = None
created_at: Optional[int] = None
filename: Optional[str] = None
object: Optional[str] = None
purpose: Optional[str] = None
status: Optional[str] = None
status_details: Optional[str] = None


class Upload(BaseModel, extra="allow"):
id: Optional[str] = None
bytes: Optional[int] = None
Expand Down

0 comments on commit 129ebf6

Please sign in to comment.