mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-24 23:54:14 +00:00
core[patch]: Message content as positional arg (#16921)
This commit is contained in:
parent
c29e9b6412
commit
d80c612c92
@ -28,6 +28,12 @@ class BaseMessage(Serializable):
|
|||||||
class Config:
|
class Config:
|
||||||
extra = Extra.allow
|
extra = Extra.allow
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, content: Union[str, List[Union[str, Dict]]], **kwargs: Any
|
||||||
|
) -> None:
|
||||||
|
"""Pass in content as positional arg."""
|
||||||
|
return super().__init__(content=content, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_lc_serializable(cls) -> bool:
|
def is_lc_serializable(cls) -> bool:
|
||||||
"""Return whether this class is serializable."""
|
"""Return whether this class is serializable."""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import List, Literal, Sequence
|
from typing import List, Literal, Sequence, cast
|
||||||
|
|
||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ class ImagePromptValue(PromptValue):
|
|||||||
|
|
||||||
def to_messages(self) -> List[BaseMessage]:
|
def to_messages(self) -> List[BaseMessage]:
|
||||||
"""Return prompt as messages."""
|
"""Return prompt as messages."""
|
||||||
return [HumanMessage(content=[self.image_url])]
|
return [HumanMessage(content=[cast(dict, self.image_url)])]
|
||||||
|
|
||||||
|
|
||||||
class ChatPromptValueConcrete(ChatPromptValue):
|
class ChatPromptValueConcrete(ChatPromptValue):
|
||||||
|
@ -446,7 +446,7 @@ class _StringImageMessagePromptTemplate(BaseMessagePromptTemplate):
|
|||||||
content=text, additional_kwargs=self.additional_kwargs
|
content=text, additional_kwargs=self.additional_kwargs
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
content = []
|
content: List = []
|
||||||
for prompt in self.prompt:
|
for prompt in self.prompt:
|
||||||
inputs = {var: kwargs[var] for var in prompt.input_variables}
|
inputs = {var: kwargs[var] for var in prompt.input_variables}
|
||||||
if isinstance(prompt, StringPromptTemplate):
|
if isinstance(prompt, StringPromptTemplate):
|
||||||
|
Loading…
Reference in New Issue
Block a user