-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add ProviderChatMessage
e.g. OpenAIChatMessage
types and coerce to message params under the hood
#311
Comments
to me, i feel like a major point of mirascope is to not have to care at all about what the providers accept in their own SDKs. so i'd ask what you think the experience you want your developers to have is completely irrespective of what the provider SDKs do. obviously |
unless you can articulate a reason that you would want your end users to have to think about this distinction. (could totally imagine |
Yes, absolutely. If I wanted to deal with the idiosyncrasies of the openai sdk, I would just use the openai sdk. I feel like the whole point here is for you to make it as clean and easy for me to use mirascope as possible, designing the best possible interface for your users completely independent of what provider sdks do, and then handle mapping that to the provider sdks under-the-hood. |
And you're ok where history will only work this way if you use |
Re: your example:
This honestly feels kinda gross to me. Some responses may follow this turn-based pattern of user message -> assistant message, but many won't. So now I need to understand that I don't know what the proper solution is here, but i feel like for something like this chatbot use case, a cleaner pattern would be something along the lines of:
|
No. Similarly, I would expect your messages handling to essentially be E.g. everywhere that i deal with messages in mirascope, I can just use the |
I really don't like this. If anything it would be more like: from mirascope.openai import OpenAICall, OpenAIChatMessage
class Chatbot(OpenAICall):
prompt_template = """
SYSTEM: You are a friendly chatbot.
MESSAGES: {history}
USER: {_input}
"""
history: list[OpenAIChatMessage]
_input: str
def chat(self, input: str) -> str:
# you already know i don't like this pattern, but not trying to include the scope of that issue in this one
self._input = input
response = self.call()
self.history += [{"role": "user", "content": input}, response.message] # since you don't like `user_message_param`
return response.content
chatbot = Chatbot()
response_text = chatbot.chat(input="hello")
print(response_text)
This we could do, and we could do it for every provider because inside of the What I meant about only working when using from mirascope.openai import OpenAICall, OpenAIChatMessage
class Chatbot(OpenAICall):
history: list[OpenAIChatMessage]
_input: str
def messages(self) -> list[OpenAIChatMessage]: # this might break things, unknown, depends on provider?
return [
{"role": "system", "content": "You are a friendly chatbot"},
*history,
{"role": "user", "content": self._input},
]
def chat(self, input: str) -> str:
# you already know i don't like this pattern, but not trying to include the scope of that issue in this one
self._input = input
response = self.call()
self.history += [{"role": "user", "content": input}, response.message] # since you don't like `user_message_param`
return response.content
chatbot = Chatbot()
response_text = chatbot.chat(input="hello")
print(response_text) At this point you've taken back control and are choosing not to take advantage of certain conveniences. But since you're writing the messages yourself, the coercion is no longer happening, and we internally need the return type of messages to be Would something like the following work in the case that you're writing your own messages? from mirascope.openai import OpenAICall, OpenAIChatMessage, convert_to_openai_message_param
from openai.types.chat import ChatCompletionMessageParam
class Chatbot(OpenAICall):
history: list[OpenAIChatMessage]
_input: str
def messages(self) -> list[ChatCompletionMessageParam]:
return [
{"role": "system", "content": "You are a friendly chatbot"},
*convert_to_openai_message_param(history),
{"role": "user", "content": self._input},
]
def chat(self, input: str) -> str:
# you already know i don't like this pattern, but not trying to include the scope of that issue in this one
self._input = input
response = self.call()
self.history += [{"role": "user", "content": input}, response.message] # since you don't like `user_message_param`
return response.content
chatbot = Chatbot()
response_text = chatbot.chat(input="hello")
print(response_text) |
Worth noting that in my head |
@jbbakst I'm feeling less sold on this having implemented the
message_param
given that usingmessage_param
matches the typing of the SDK (even though it technically accepts the response message type) and provides a common interface across providers where sometimes you can't pass the message in directly.Originally posted by @willbakst in #264 (comment)
The text was updated successfully, but these errors were encountered: