Skip to content

Commit fb3f2c4

Browse files
authored
fix(drivers-prompt-openai): convert to text rather than error when passing GenericArtifacts (#1830)
1 parent 57ef8f9 commit fb3f2c4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

griptape/drivers/prompt/openai_chat_prompt_driver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def __to_openai_message_content(self, content: BaseMessageContent) -> str | dict
352352
elif isinstance(content, ActionResultMessageContent):
353353
return content.artifact.to_text()
354354
else:
355-
raise ValueError(f"Unsupported content type: {type(content)}")
355+
return {"type": "text", "text": content.artifact.to_text()}
356356

357357
def __to_prompt_stack_message_content(self, response: ChatCompletionMessage) -> list[BaseMessageContent]:
358358
content = []

tests/unit/drivers/prompt/test_openai_chat_prompt_driver.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from griptape.artifacts import ActionArtifact, ImageArtifact, ListArtifact, TextArtifact
99
from griptape.artifacts.audio_artifact import AudioArtifact
10+
from griptape.artifacts.generic_artifact import GenericArtifact
1011
from griptape.common import ActionCallDeltaMessageContent, PromptStack, TextDeltaMessageContent, ToolAction
1112
from griptape.common.prompt_stack.contents.audio_delta_message_content import AudioDeltaMessageContent
1213
from griptape.drivers.prompt.openai import OpenAiChatPromptDriver
@@ -366,6 +367,8 @@ def prompt_stack(self):
366367
},
367368
),
368369
)
370+
371+
prompt_stack.add_user_message(GenericArtifact(value="generic-value"))
369372
return prompt_stack
370373

371374
@pytest.fixture()
@@ -402,6 +405,7 @@ def messages(self):
402405
},
403406
{"audio": {"id": "audio-id"}, "content": "", "role": "assistant"},
404407
{"content": [{"type": "text", "text": "assistant-audio-transcription"}], "role": "assistant"},
408+
{"content": [{"type": "text", "text": "generic-value"}], "role": "user"},
405409
]
406410

407411
@pytest.fixture()

0 commit comments

Comments
 (0)