Files changed (1) hide show
  1. main.py +36 -8
main.py CHANGED
@@ -1,21 +1,49 @@
1
- #pip install fastapi
2
- #uvicorn main:app --reload
3
- #import gradio as gr
4
-
5
- from transformers import pipeline
6
  from fastapi import FastAPI
7
 
8
  app = FastAPI()
9
 
10
- #generator = pipeline('text-generation',model='gpt2')
11
  #generator = pipeline('text-generation',model='Open-Orca/Mistral-7B-OpenOrca')
12
- generator = pipeline("text-generation", model="lmsys/vicuna-7b-v1.5")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  @app.get("/")
16
  async def root():
17
- return {"message": "Hello World"}
18
  #return generator('What is love',max_length=100, num_return_sequences=1)
 
19
 
20
  @app.post("/predict")
21
  async def root(text):
 
1
+ #from transformers import pipeline
 
 
 
 
2
  from fastapi import FastAPI
3
 
4
  app = FastAPI()
5
 
 
6
  #generator = pipeline('text-generation',model='Open-Orca/Mistral-7B-OpenOrca')
7
+
8
+
9
+
10
+ from haystack.document_stores import InMemoryDocumentStore
11
+ from haystack.utils import build_pipeline, add_example_data, print_answers
12
+
13
+ # We are model agnostic :) Here, you can choose from: "anthropic", "cohere", "huggingface", and "openai".
14
+ provider = "openai"
15
+ API_KEY = "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" # ADD YOUR KEY HERE
16
+
17
+ # We support many different databases. Here we load a simple and lightweight in-memory database.
18
+ document_store = InMemoryDocumentStore(use_bm25=True)
19
+
20
+ # Download and add Game of Thrones TXT articles to Haystack DocumentStore.
21
+ # You can also provide a folder with your local documents.
22
+ #add_example_data(document_store, "data/GoT_getting_started")
23
+ add_example_data(document_store, "/content/Books")
24
+
25
+ # Build a pipeline with a Retriever to get relevant documents to the query and a PromptNode interacting with LLMs using a custom prompt.
26
+ pipeline = build_pipeline(provider, API_KEY, document_store)
27
+
28
+ # Ask a question on the data you just added.
29
+ result = pipeline.run(query="What is job yoga?")
30
+
31
+ # For details, like which documents were used to generate the answer, look into the <result> object
32
+ #print_answers(result, details="medium")
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
 
41
 
42
  @app.get("/")
43
  async def root():
44
+ #return {"message": "Hello World"}
45
  #return generator('What is love',max_length=100, num_return_sequences=1)
46
+ return print_answers(result, details="medium")
47
 
48
  @app.post("/predict")
49
  async def root(text):