Skip to content
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

Load Existing Messages into Chat Playground #637

Open
brycecoldcocacola opened this issue May 8, 2024 · 2 comments
Open

Load Existing Messages into Chat Playground #637

brycecoldcocacola opened this issue May 8, 2024 · 2 comments
Labels
enhancement New feature or request playground

Comments

@brycecoldcocacola
Copy link

brycecoldcocacola commented May 8, 2024

I don't see a way to start the chat playground with an initial AI message. Use-case here is to explore conversations where the bot will initiate the conversation.

So if I have something like this as a full example:

import datetime as dt

from fastapi import FastAPI
from langserve import add_routes
from langchain_core.prompts.chat import ChatPromptTemplate, MessagesPlaceholder
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_openai import ChatOpenAI
from langchain.tools import tool
from langchain.pydantic_v1 import BaseModel, Field
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage

@tool
def schedule_session(appointment_time: dt.datetime) -> str:
    """Schedule a session with the user."""
    return "ok"

tools = [schedule_session]

gpt_35_turbo = ChatOpenAI(model="gpt-3.5-turbo")

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are an empathetic bot reaching out to a friend"),
        ("ai", "Hey Jessica! Just wanted to check in on you. How are you doing?"),
        MessagesPlaceholder("chat_history", optional=True),
        ("human", "{input} {agent_scratchpad}"),
    ]
)

agent = create_tool_calling_agent(llm=gpt_35_turbo, tools=tools, prompt=prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

class ChatInputWithHistory(BaseModel):
    """Input for the chat endpoint."""
    input: str
    chat_history: list[HumanMessage | AIMessage | SystemMessage] = Field(
        ...,
        description="The chat messages representing the current conversation.",
    )

playground_compatible_agent_executor = (
    agent_executor | (lambda x: x["output"])
).with_types(input_type=ChatInputWithHistory, output_type=str)

app = FastAPI()

add_routes(
        app,
        playground_compatible_agent_executor,
        path="/chat",
        playground_type="chat",
)

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)

Then I would expect my http://localhost:8080/nova/chat/playground/ to open like this:

Screenshot 2024-05-08 at 2 15 35 PM

Because I specified ("ai", "Hey Jessica! Just wanted to check in on you. How are you doing?") in my chat prompt.

@brycecoldcocacola
Copy link
Author

related: #598 (comment)

@eyurtsev
Copy link
Collaborator

There's no way to do this currently :(

@eyurtsev eyurtsev added enhancement New feature or request playground labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request playground
Projects
None yet
Development

No branches or pull requests

2 participants