yash-srivastava19 commited on
Commit
3723d1a
·
1 Parent(s): 6b5d205

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain import PromptTemplate, LLMChain
2
+ import chainlit as cl
3
+ from custom_llm import CustomLLM
4
+ from langchain.prompts import (
5
+ ChatPromptTemplate,
6
+ SystemMessagePromptTemplate,
7
+ )
8
+
9
+ template = """ Write a code for the following problem :
10
+ {question}
11
+
12
+ Code:
13
+ """
14
+
15
+
16
+ @cl.langchain_factory(use_async=False)
17
+ def factory():
18
+ system_message_prompt = SystemMessagePromptTemplate.from_template(template)
19
+
20
+ prompt = ChatPromptTemplate.from_messages([system_message_prompt])
21
+ llm = CustomLLM()
22
+
23
+ llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True,)
24
+
25
+ cl.user_session.set("llm_chain", llm_chain)
26
+ return llm_chain
27
+
28
+
29
+ @cl.langchain_rename # This will be particularly useful when we want to customize this thing for production.
30
+ def rename(orig_author):
31
+ rename_dict = {
32
+ 'LLMChain': 'Scooby'
33
+ }
34
+ return rename_dict.get(orig_author, orig_author)
35
+
36
+
37
+ @cl.on_chat_start
38
+ async def main():
39
+ await cl.Message(content="Welcome to CodeSmith !! Let's start this").send()