Spaces:
Paused
Paused
Update endpoints.py
Browse files- endpoints.py +38 -32
endpoints.py
CHANGED
@@ -6,17 +6,6 @@ import os
|
|
6 |
import requests
|
7 |
# from langchain.llms.huggingface_pipeline import HuggingFacePipeline
|
8 |
|
9 |
-
key = os.environ.get("huggingface_key")
|
10 |
-
openai_api_key = os.environ.get("openai_key")
|
11 |
-
app = FastAPI(openapi_url="/api/v1/LLM/openapi.json", docs_url="/api/v1/LLM/docs")
|
12 |
-
|
13 |
-
app.add_middleware(
|
14 |
-
CORSMiddleware,
|
15 |
-
allow_origins=["*"],
|
16 |
-
allow_methods=["*"],
|
17 |
-
allow_headers=["*"],
|
18 |
-
allow_credentials=True,
|
19 |
-
)
|
20 |
# API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-v0.1"
|
21 |
# headers = {"Authorization": f"Bearer {key}"}
|
22 |
|
@@ -24,33 +13,34 @@ app.add_middleware(
|
|
24 |
# response = requests.post(API_URL, headers=headers, json=payload)
|
25 |
# return response.json()
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
44 |
|
45 |
# tokenizer = AutoTokenizer.from_pretrained("WizardLM/WizardCoder-1B-V1.0")
|
46 |
# base_model = AutoModelForCausalLM.from_pretrained("WizardLM/WizardCoder-1B-V1.0")
|
47 |
# Mistral 7B
|
48 |
-
mistral_llm = LLM("mistralai/Mistral-7B-v0.1",30000)
|
49 |
-
|
50 |
|
51 |
# WizardCoder 13B
|
52 |
-
wizard_llm = LLM("WizardLM/WizardCoder-Python-13B-V1.0",8000)
|
53 |
-
|
54 |
# hf_llm = HuggingFacePipeline(pipeline=pipe)
|
55 |
|
56 |
def ask_model(model, prompt):
|
@@ -61,6 +51,22 @@ def ask_model(model, prompt):
|
|
61 |
|
62 |
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
@app.get("/")
|
65 |
def root():
|
66 |
return {"message": "R&D LLM API"}
|
|
|
6 |
import requests
|
7 |
# from langchain.llms.huggingface_pipeline import HuggingFacePipeline
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-v0.1"
|
10 |
# headers = {"Authorization": f"Bearer {key}"}
|
11 |
|
|
|
13 |
# response = requests.post(API_URL, headers=headers, json=payload)
|
14 |
# return response.json()
|
15 |
|
16 |
+
# def LLM(llm_name, length):
|
17 |
+
# print(llm_name)
|
18 |
+
# tokenizer = AutoTokenizer.from_pretrained(llm_name)
|
19 |
+
# model = AutoModelForCausalLM.from_pretrained(llm_name)
|
20 |
+
# pipe = pipeline("text-generation",
|
21 |
+
# model=model,
|
22 |
+
# tokenizer=tokenizer,
|
23 |
+
# max_length=length,
|
24 |
+
# do_sample=True,
|
25 |
+
# top_p=0.95,
|
26 |
+
# repetition_penalty=1.2,
|
27 |
+
# )
|
28 |
+
# return pipe
|
29 |
+
# Load model directly
|
30 |
+
# Use a pipeline as a high-level helper
|
31 |
+
from transformers import pipeline
|
32 |
+
|
33 |
+
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-v0.1")
|
34 |
|
35 |
# tokenizer = AutoTokenizer.from_pretrained("WizardLM/WizardCoder-1B-V1.0")
|
36 |
# base_model = AutoModelForCausalLM.from_pretrained("WizardLM/WizardCoder-1B-V1.0")
|
37 |
# Mistral 7B
|
38 |
+
# mistral_llm = LLM("mistralai/Mistral-7B-v0.1",30000)
|
39 |
+
mistral_llm = pipe
|
40 |
|
41 |
# WizardCoder 13B
|
42 |
+
# wizard_llm = LLM("WizardLM/WizardCoder-Python-13B-V1.0",8000)
|
43 |
+
wizard_llm = pipe
|
44 |
# hf_llm = HuggingFacePipeline(pipeline=pipe)
|
45 |
|
46 |
def ask_model(model, prompt):
|
|
|
51 |
|
52 |
|
53 |
|
54 |
+
|
55 |
+
|
56 |
+
|
57 |
+
key = os.environ.get("huggingface_key")
|
58 |
+
openai_api_key = os.environ.get("openai_key")
|
59 |
+
app = FastAPI(openapi_url="/api/v1/LLM/openapi.json", docs_url="/api/v1/LLM/docs")
|
60 |
+
|
61 |
+
app.add_middleware(
|
62 |
+
CORSMiddleware,
|
63 |
+
allow_origins=["*"],
|
64 |
+
allow_methods=["*"],
|
65 |
+
allow_headers=["*"],
|
66 |
+
allow_credentials=True,
|
67 |
+
)
|
68 |
+
|
69 |
+
|
70 |
@app.get("/")
|
71 |
def root():
|
72 |
return {"message": "R&D LLM API"}
|