Skip to content

Commit

Permalink
Create Dash-Langchain-app1.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-with-Adam authored Oct 18, 2023
1 parent e84c25e commit 11dfc81
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Blog/Dash-Langchain-app1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from dash import Dash, dcc, html, callback, Input, Output
from langchain.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI

prompt = ChatPromptTemplate.from_template("tell me a joke about {foo}")
api_key = "my-api-key-goes-here"
model = ChatOpenAI(openai_api_key=api_key)
chain = prompt | model

app = Dash()

app.layout = html.Div([
html.H1("Joke-Generating App"),
html.Label("Tell me a joke about: "),
dcc.Input(id='subject', debounce=True, maxLength=15),
html.Hr(),
html.Div(id='joke-placeholder')
])

@callback(
Output('joke-placeholder', 'children'),
Input('subject', 'value'),
prevent_initial_call=True
)
def update_layout(input_value):
joke = chain.invoke({"foo": input_value})
output = joke.content
return output


if __name__ == "__main__":
app.run_server(debug=True)

0 comments on commit 11dfc81

Please sign in to comment.