-
Notifications
You must be signed in to change notification settings - Fork 393
use settings for some defaults, avoid warnings #682
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ def cast_type_to_model( | |
|
|
||
| return create_model( | ||
| model_name, | ||
| __doc__=model_description, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. model_description was unused |
||
| __config__=None, | ||
| __base__=None, | ||
| __module__=__name__, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,12 @@ | |
| from pydantic import BaseModel, ConfigDict, Field | ||
| from typing_extensions import NotRequired, ParamSpec, Self, Unpack | ||
|
|
||
| import marvin | ||
| from marvin._mappings.chat_completion import chat_completion_to_model | ||
| from marvin.client.openai import AsyncMarvinClient, MarvinClient | ||
| from marvin.components.prompt.fn import PromptFunction | ||
| from marvin.utilities.jinja import BaseEnvironment | ||
| from marvin.utilities.logging import get_logger | ||
|
|
||
| if TYPE_CHECKING: | ||
| from openai.types.chat import ChatCompletion | ||
|
|
@@ -44,17 +46,17 @@ class AIFunctionKwargs(TypedDict): | |
|
|
||
|
|
||
| class AIFunctionKwargsDefaults(BaseModel): | ||
| model_config = ConfigDict(arbitrary_types_allowed=True) | ||
| model_config = ConfigDict(arbitrary_types_allowed=True, protected_namespaces=()) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid warning about infringing on sacred |
||
| environment: Optional[BaseEnvironment] = None | ||
| prompt: Optional[str] = None | ||
| model_name: str = "FormatResponse" | ||
| model_description: str = "Formats the response." | ||
| field_name: str = "data" | ||
| field_description: str = "The data to format." | ||
| model: Optional[str] = None | ||
| model: str = marvin.settings.openai.chat.completions.model | ||
| client: Optional[Client] = None | ||
| aclient: Optional[AsyncClient] = None | ||
| temperature: Optional[float] = None | ||
| temperature: Optional[float] = marvin.settings.openai.chat.completions.temperature | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was getting 400s without these |
||
|
|
||
|
|
||
| class AIFunction( | ||
|
|
@@ -89,6 +91,10 @@ class AIFunction( | |
| client: Client = Field(default_factory=lambda: MarvinClient().client) | ||
| aclient: AsyncClient = Field(default_factory=lambda: AsyncMarvinClient().client) | ||
|
|
||
| @property | ||
| def logger(self): | ||
| return get_logger(self.__class__.__name__) | ||
|
|
||
| def __call__( | ||
| self, *args: P.args, **kwargs: P.kwargs | ||
| ) -> Union[T, Coroutine[Any, Any, T]]: | ||
|
|
@@ -101,6 +107,7 @@ def call(self, *args: P.args, **kwargs: P.kwargs) -> T: | |
| response: ChatCompletion = MarvinClient(client=self.client).chat( | ||
| **prompt.serialize() | ||
| ) | ||
| self.logger.debug_kv("Calling", f"{self.fn.__name__}({args}, {kwargs})", "blue") | ||
| return getattr( | ||
| chat_completion_to_model(model, response, field_name=self.field_name), | ||
| self.field_name, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was unreachable