-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for older chat input schemas to chat playground (#526)
- Loading branch information
1 parent
4bf7b0f
commit 1428ac0
Showing
10 changed files
with
178 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
"""Example of a simple chatbot that just passes current conversation | ||
state back and forth between server and client. | ||
""" | ||
from typing import List, Union | ||
|
||
from fastapi import FastAPI | ||
from langchain.chat_models import ChatAnthropic | ||
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage | ||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder | ||
|
||
from langserve import add_routes | ||
from langserve.pydantic_v1 import BaseModel, Field | ||
|
||
app = FastAPI( | ||
title="LangChain Server", | ||
version="1.0", | ||
description="Spin up a simple api server using Langchain's Runnable interfaces", | ||
) | ||
|
||
|
||
# Declare a chain | ||
prompt = ChatPromptTemplate.from_messages( | ||
[ | ||
("system", "You are a helpful, professional assistant named Cob."), | ||
MessagesPlaceholder(variable_name="messages"), | ||
("human", "{input}"), | ||
] | ||
) | ||
|
||
chain = prompt | ChatAnthropic(model="claude-2") | ||
|
||
|
||
class InputChat(BaseModel): | ||
"""Input for the chat endpoint.""" | ||
|
||
messages: List[Union[HumanMessage, AIMessage, SystemMessage]] = Field( | ||
..., | ||
description="The chat messages representing the current conversation.", | ||
) | ||
|
||
input: str | ||
|
||
|
||
add_routes( | ||
app, | ||
chain.with_types(input_type=InputChat), | ||
enable_feedback_endpoint=True, | ||
enable_public_trace_link_endpoint=True, | ||
playground_type="chat", | ||
) | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
|
||
uvicorn.run(app, host="localhost", port=8000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
48 changes: 24 additions & 24 deletions
48
..._playground/dist/assets/index-c5f8c3dc.js → ..._playground/dist/assets/index-d9089d96.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters