Commit
·
64201df
1
Parent(s):
a839a97
Delete Stbotchainlit.py
Browse files- Stbotchainlit.py +0 -90
Stbotchainlit.py
DELETED
|
@@ -1,90 +0,0 @@
|
|
| 1 |
-
from langchain import PromptTemplate, LLMChain
|
| 2 |
-
from langchain import OpenAI, LLMMathChain, SerpAPIWrapper
|
| 3 |
-
from langchain.agents import initialize_agent, Tool, AgentExecutor
|
| 4 |
-
from langchain.chat_models import ChatOpenAI
|
| 5 |
-
import os
|
| 6 |
-
import chainlit as cl
|
| 7 |
-
from langchain.chat_models import ChatOpenAI
|
| 8 |
-
from langchain.agents import load_tools, initialize_agent, AgentType
|
| 9 |
-
import os
|
| 10 |
-
from langchain.chat_models import ChatOpenAI
|
| 11 |
-
from langchain.agents import initialize_agent
|
| 12 |
-
from langchain.agents import AgentType
|
| 13 |
-
import os
|
| 14 |
-
from langchain.tools import ShellTool
|
| 15 |
-
from langchain.tools import YouTubeSearchTool
|
| 16 |
-
from langchain.agents import initialize_agent, Tool
|
| 17 |
-
from langchain.agents import AgentType
|
| 18 |
-
from langchain.llms import OpenAI
|
| 19 |
-
from langchain import LLMMathChain, SerpAPIWrapper
|
| 20 |
-
import os
|
| 21 |
-
from chainlit.types import AskFileResponse
|
| 22 |
-
import chainlit as cl
|
| 23 |
-
from langchain.chat_models import ChatOpenAI
|
| 24 |
-
from langchain.chains import RetrievalQAWithSourcesChain
|
| 25 |
-
from langchain.vectorstores import Chroma
|
| 26 |
-
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 27 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 28 |
-
from langchain.document_loaders import PyPDFLoader, TextLoader
|
| 29 |
-
import os
|
| 30 |
-
import openai
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
os.environ['OPENAI_API_KEY'] = "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"
|
| 34 |
-
OpenAI.api_key = "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"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
template = """Question: {question}
|
| 38 |
-
Answer: Let's think step by step."""
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
@cl.langchain_factory(use_async=True)
|
| 42 |
-
def factory():
|
| 43 |
-
prompt = PromptTemplate(template=template, input_variables=["question"])
|
| 44 |
-
llm_chain = LLMChain(prompt=prompt, llm=ChatOpenAI(
|
| 45 |
-
temperature=0, streaming=True))
|
| 46 |
-
return llm_chain
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
def get_gpt_output(user_message):
|
| 50 |
-
response = openai.ChatCompletion.create(
|
| 51 |
-
model="gpt-4",
|
| 52 |
-
messages=[
|
| 53 |
-
{"role": "system", "content": "you are an writer that is obsessed with storytelling and will never stop talking about it"},
|
| 54 |
-
{"role": "user", "content": user_message}
|
| 55 |
-
],
|
| 56 |
-
temperature=1,
|
| 57 |
-
max_tokens=256,
|
| 58 |
-
top_p=1,
|
| 59 |
-
frequency_penalty=0,
|
| 60 |
-
presence_penalty=0
|
| 61 |
-
)
|
| 62 |
-
|
| 63 |
-
return response
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
@cl.on_message
|
| 67 |
-
async def main(message: str):
|
| 68 |
-
await cl.Message(content=f"{get_gpt_output(message)['choices'][0]['message']['content']}",).send()
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
#! pip install youtube_search
|
| 72 |
-
tool = YouTubeSearchTool()
|
| 73 |
-
|
| 74 |
-
tools = [
|
| 75 |
-
Tool(
|
| 76 |
-
name="Search",
|
| 77 |
-
func=tool.run,
|
| 78 |
-
description="useful for when you need to give links to youtube videos. Remember to put https://youtube.com/ in front of every link to complete it",
|
| 79 |
-
)
|
| 80 |
-
]
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
agent = initialize_agent(
|
| 84 |
-
tools,
|
| 85 |
-
OpenAI(temperature=0),
|
| 86 |
-
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 87 |
-
verbose=True,
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
agent.run('Whats a good vido on the topic of dialogue')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|