File size: 871 Bytes
d6cf387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from langchain_ai21 import ChatAI21
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

# 1. Set up your AI21 API key
os.environ["AI21_API_KEY"] = "your-ai21-api-key"

# 2. Create a prompt template for the chatbot
prompt = PromptTemplate(
    input_variables=["user_input"],
    template="""
    You are a helpful and friendly chatbot. Respond concisely and informatively.

    User: {user_input}
    Chatbot:
    """
)


from langchain.memory import ConversationBufferMemory

memory = ConversationBufferMemory()
chat_chain = LLMChain(llm=llm, prompt=prompt, memory=memory)

llm.streaming = True

import gradio as gr

def chatbot_response(user_input):
    return chat_chain.run({"user_input": user_input})

gr.Interface(
    fn=chatbot_response,
    inputs="text",
    outputs="text",
    title="AI Chatbot with Jamba"
).launch()