antitheft159 commited on
Commit
1de8870
·
verified ·
1 Parent(s): 968f4d9

Upload mohanism_195 (1).py

Browse files
Files changed (1) hide show
  1. mohanism_195 (1).py +111 -0
mohanism_195 (1).py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """mohanism.195
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1AvIdAQmhCWUUe6rT9sck2gBGkecNCjEc
8
+ """
9
+
10
+ !pip install dotenv
11
+
12
+ from dotenv import load_dotenv,find_dotenv
13
+ load_dotenv(find_dotenv())
14
+
15
+ from langchain.llns import OpenAI
16
+ llm = OpenAI(model_name="text-davinci-003")
17
+ llm("explain large language models in one sentence")
18
+
19
+ from langchain.schema import (
20
+ AIMessage,
21
+ HumanMessage,
22
+ SystemMessage
23
+ )
24
+ from langchain.chat_models import ChatOpenAI
25
+
26
+ chat = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3)
27
+ messages = (
28
+ SystemMessage(content="You are an expert data scientist"),
29
+ HumanMessage(content="Write a Python script that trains a neural network on simulated data ")
30
+ )
31
+ response=chat(messages)
32
+
33
+ print(response.content,ends="\n")
34
+
35
+ from langchain import PromptTemplate
36
+
37
+ template = """You are an expert data scientist with an expertise in building deep learning models,
38
+ Explain the concept of {concept} in a couple of lines
39
+ """
40
+
41
+ prompt = PromptTemplate(
42
+ input_variable=["concept"],
43
+ template=template,
44
+ )
45
+
46
+ prompt
47
+
48
+ llm(prompt.format(concept="autoencoder"))
49
+
50
+ from langchain.chains import LLMChain
51
+ chain = LLMchain(llm=lln, prompt=prompt)
52
+
53
+ second_prompt = PromptTemplate(
54
+ input_variables=["ml_concept"],
55
+ template="Turn the concept description of {ml_concept} and explain it to me like I'm five in 500 words",
56
+ )
57
+ chain_two = LLMChain(llm=llm, prompt=second_prompt)
58
+
59
+ from langchain.chains import SimpleSequenttialChain
60
+ overall_chain = SimpleSequenttialChain(chains=[chain, chain_two], verbose=True)
61
+
62
+ explanation = overall_chain.run("autoencoder")
63
+ print(explanation)
64
+
65
+ from langchain.text_splitter importRecursiveCharacterTextSplitter
66
+
67
+ text_splitter = RecursiveCharacterTextSplitter(
68
+ chunk_size = 100,
69
+ chunk_overlap = 0,
70
+ )
71
+
72
+ text = text_splitter.create_documents([explanation])
73
+
74
+ text[0].page_content
75
+
76
+ from langchain.embeddings import OpenAIEmbeddings
77
+
78
+ embeddings = OpenAIEmbeddings(model_name="ada")
79
+
80
+ query_result = embeddings.embed_query(texts[0].page_content)
81
+ query_result
82
+
83
+ import os
84
+ import pinecome
85
+ from langchain.vectors import Pinecone
86
+
87
+ # initialize pinecome
88
+ pinecome.init(
89
+ api_key=os.getenv["PINECONE_API_KEY"],
90
+ environment(=os.getenv("PINECONE_ENV")
91
+ )
92
+
93
+ index_name = "langchain-quickstart"
94
+ search = Pinecone.form_documents(texts, embeddings, index_name=index_name)
95
+
96
+ query = "What is magical about an autoencoder?"
97
+ result = search.similarity_search(query)
98
+
99
+ result
100
+
101
+ from langhain.agent.agent_toolkets import create_python_agent
102
+ from langchain.tools.python.tool import PythonREPLTool
103
+ from langchain.python import PythonREPL
104
+ from langchain.llms.openai import OpenAI
105
+
106
+ agent_executor = create_python_agent(
107
+ llm=OpenAI(temperature=0), max_tokens=1000),
108
+ verbose=True
109
+ )
110
+
111
+ agent_executor.run("Find the roots (zeros) if the quadratic function 3 * x==2 + 2** - 1")