Utkarsh-Tiwari commited on
Commit
fc46e61
·
1 Parent(s): 323d23c

upload fine tune

Browse files
Files changed (1) hide show
  1. fine-tune.py +58 -0
fine-tune.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain.embeddings.openai import OpenAIEmbeddings
3
+ from langchain.vectorstores import DeepLake
4
+ from langchain.text_splitter import CharacterTextSplitter
5
+ from langchain.document_loaders import SeleniumURLLoader
6
+ from langchain import PromptTemplate
7
+ from apscheduler.schedulers.background import BackgroundScheduler
8
+
9
+ def embedding():
10
+ os.environ['OPENAI_API_KEY'] = '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'
11
+ os.environ["ACTIVELOOP_TOKEN"] = "eyJhbGciOiJIUzUxMiIsImlhdCI6MTY5NTE5MTAyNiwiZXhwIjoxNzU4MzQ5NDA3fQ.eyJpZCI6InV0a2Fyc2h0aXdhcmkifQ.PK_iz7uybeSmgqFvOYrICw-CQDbDY1aOjYhkMu-0Jle6gU33dCwxah7bmy39O0hPN4jYLu_RfLuU-XejyNvXrw"
12
+
13
+ #llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613')
14
+
15
+ # URLs of articles to scrape
16
+ urls = ["https://modelwise.ai/product/","https://modelwise.ai/category/blog-articles/","https://modelwise.ai/company/"]
17
+
18
+ # Load documents using Selenium
19
+ loader = SeleniumURLLoader(urls=urls)
20
+ docs_not_splitted = loader.load()
21
+
22
+ # Split documents into smaller chunks
23
+ text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
24
+ docs = text_splitter.split_documents(docs_not_splitted)
25
+
26
+ # Create OpenAIEmbeddings instance
27
+ embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
28
+
29
+ # Specify your ActiveLoop organization ID
30
+ my_activeloop_org_id = "utkarshtiwari"
31
+ my_activeloop_dataset_name = "chatbot_modelwise"
32
+ dataset_path = f"hub://{my_activeloop_org_id}/{my_activeloop_dataset_name}"
33
+ db = DeepLake(dataset_path=dataset_path, embedding_function=embeddings)
34
+
35
+ # Add documents to the Deep Lake dataset
36
+ db.add_documents(docs)
37
+
38
+ template = """You are an exceptional customer support chatbot for the company Modelwise that gently answers questions related to the company.
39
+
40
+ You know the following context information.
41
+
42
+ {chunks_formatted}
43
+
44
+ Answer the following question from a customer. Use only information from the context. If you don't know the answer just ask the customer to contact Arnold and provide his contact details. Do not make up any answer.
45
+
46
+ Question: {query}
47
+
48
+ Answer:"""
49
+
50
+ # Create a PromptTemplate instance
51
+ prompt = PromptTemplate(
52
+ input_variables=["chunks_formatted", "query"],
53
+ template=template,
54
+ )
55
+
56
+ scheduler = BackgroundScheduler()
57
+ scheduler.add_job(func=embedding, trigger="interval", seconds=60)
58
+ scheduler.start()